LoginSignup
14
14

More than 5 years have passed since last update.

ipythonをMavericksに入れてみた

Last updated at Posted at 2014-05-07

ipythonはpythonのオリジナルのpythonインタプリタよりもハイライトや履歴管理など便利な機能を兼ね備えたツールである。今回はこれをMac OS X 10.9 (Mavericks)に入れてみる。

いろいろと入れ方はあるようだが、pipで入れるのが一番楽そうだ。

インストール

$ pip install ipython

動作確認

コマンドラインから実行して、以下のようなプロンプトがでてきたら、成功

$ ipython
Python 2.7.3 (default, Nov  1 2013, 14:34:21) 
Type "copyright", "credits" or "license" for more information.

IPython 2.0.0 -- 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]: 

ipython notebookのインストール

ipythonだけなら、このまま使えるが、ipython notebookを使いたい場合はいくつか追加でパッケージのインストールが必要となる。ipython notebookはブラウザ上からコードの編集・実行・表示ができるツールで直感的にpythonのコード実行を確認できる。

$ pip install pyzmq
$ pip install tornado
$ pip install jinja2

※なお、ビルドに必要なXcode command line toolsは既にインストール済みであることとする。

上記のパッケージを入れた上で、以下の実行することでnotebookを起動できる。

$ ipython notebook

外部からアクセス可能にする。

このままだと、自分で検証する専用になるが、外部で公開したい場合は、ホームディレクトリ中にある.ipythonの設定をいじることになる。

まず、

$ ipython profile create nbserver

と実行して、.ipythonの下に、profile_nbserverというディレクトリを作成する。

後は、その中のipython_notebook_config.pyを編集する。編集すべき項目は以下の通り。

# Kernel config
c.IPKernelApp.pylab = 'inline'  # if you want plotting support always
# Notebook config
c.NotebookApp.certfile = u'/absolute/path/to/your/certificate/mycert.pem'
c.NotebookApp.ip = '*'
c.NotebookApp.open_browser = False
c.NotebookApp.password = u'sha1:bcd259ccf...your hashed password here'
# It's a good idea to put it on a known, fixed port
c.NotebookApp.port = 9999

NotebookApp.passwordの部分は、ipythonで生成すると良い。

$ ipython
…
In [1]: from IPython.lib import password
        password()

実行すると、パスワードを入力するように求められ、最終的に”sha1:…”が出力される。それを上記のc.Notebook.passwordに入力として与えると良い。セキュリティとしては、弱いがcertfileをコメントアウトすると、文字列認証でロックされたprofile設定が出来上がる。

後は、ipython実行時にprofileを指定すれば良い。

$ ipython notebook —profile=nbserver
14
14
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
14
14