2
2

More than 5 years have passed since last update.

デフォルトのインタラクティブシェルをIPythonにする

Last updated at Posted at 2012-04-16

pythonにipythonへのエイリアスを設置してもいいが、複数の環境で使うにはipythonが存在するかをチェックして、あればipythonを使い、なければそのままのシェルを使うようにする方がいい。

方法

pythonインタプリタは起動されるとPYTHONSTARTUPで指定されたファイルを実行する。その中でipythonを起動するだけ。

.zshrc
export PYTHONSTARTUP=$HOME/.pythonrc
.pythonrc
try:
    from IPython.frontend.terminal.ipapp import launch_new_instance
    launch_new_instance()
    raise SystemExit
except ImportError:
    # ipythonがインストールされていない場合
    pass

実行するとこんな感じになる

$ python
Python 2.7.2 (default, Feb 16 2012, 15:37:03) 
[GCC 4.2.1 (Based on Apple Inc. build 5658) (LLVM build 2335.15.00)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
Python 2.7.2 (default, Feb 16 2012, 15:37:03) 
Type "copyright", "credits" or "license" for more information.

IPython 0.12 -- 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.

In [1]: 
2
2
0

Register as a new user and use Qiita more conveniently

  1. You get articles that match your needs
  2. You can efficiently read back useful information
  3. You can use dark theme
What you can do with signing up
2
2