武器商人@Pythonのブログ

Pythonを好んで使っているプログラマです。Pythonこそが最強のプログラミング言語だと思っています。Pythonは使いやすいです。Pythonは書きやすいです。Pythonは読みやすいです。Pythonはパワフルです。Pythonは一貫性があります。Pythonが好きです。

IPython プロファイルを作成/削除/変更

スポンサーリンク

IPythonのインストールについて

http://oneshotlife-python.hatenablog.com/entry/install_IPython
上記を参照下さい。

プロファイルについて

基本的に、プログラムは全ユーザーに適用させる。特定のユーザーにだけ設定を適用させたい場合はプロファイルを作成すると便利。

プロファイルの作成方法

C:\Users\oneshot>ipython profile create oneshotlife_tom
[ProfileCreate] Generating default config file: u'C:\\Users\\oneshot\\.ipython\\profile_oneshotlife_tom\\ipython_config.py'
[ProfileCreate] Generating default config file: u'C:\\Users\\oneshot\\.ipython\\profile_oneshotlife_tom\\ipython_kernel_config.py'

プロファイルの削除方法

コマンドは特に用意されていない様子。
フォルダを削除するしか無いっぽい。

プロファイルのカスタマイズ

ipython_config.pyを開いてみると、設定項目がいろいろと列挙されており、デフォルトではコメントアウトされている。マニュアルや書籍などは無いようなので、コメントアウトされたスクリプトを元にいろいろといじってみると良さそうだ。

参考までに、プロンプトの表示をいじってみた。デフォルトだと"In [1]:"のように表示がされるが、私は数字が入るのを好まない。ブログなどに引用するときに、中途半端な数字だと嫌なので。。。

# Input prompt. '\#' will be transformed to the prompt number
c.PromptManager.in_template = 'In =>'

# Output prompt. '\#' will be transformed to the prompt number
c.PromptManager.out_template = 'Out =>'

こんな感じにしてみた。

プロファイルを指定して実行

C:\Users\oneshot>ipython --profile='oneshotlife_tom'
Python 2.7.10 (default, May 23 2015, 09:40:32) [MSC v.1500 32 bit (Intel)]
Type "copyright", "credits" or "license" for more information.

IPython 4.1.2 -- An enhanced Interactive Python.
?         -> Introduction and overview of IPython's features.
%quickref -> Quick reference.
help      -> Python's own help system.
object?   -> Details about 'object', use 'object??' for extra details.

IPython profile: oneshotlife_tom

In =>print "Hello,World!"
Hello,World!

ランチャーなんて作ってみたり

Windowsの人限定だが、batファイルなんかを作ると起動が便利だと思う。
ipython_oneshotlife_tom.cmd

ipython --profile='oneshotlife_tom'

IPythonについてもっと知りたい方は

Learning IPython for Interactive Computing and Data Visualization - Second Edition
洋書しかないけど。。。