はじめに
Jupyter NotebookのModuleで簡単にネットワーク図を作成できるPythonライブラリのnwdiagが
ipthon-diagsという形で出ています。
ただ、最終更新が2013年と古いため、
Dockerで配布されているJupyter Notebook(Python3.6の環境)でipython-diagsを試したところ、
Python3.6上では動かないモジュールでした。(Unicode Encode Errorが発生)
そこで、修正個所は多くなかったので、動くように直しました。
https://gist.github.com/a8e8269d4331b6b93e7ef90744fe0b3b.git
この記事ではそのコードのJupyter Notebookへの適応手順を記載します。
手順
- Docker imageをPullする
shell
docker pull jupyter/datascience-notebook
- Dockerコンテナを起動する
shell
docker run -d --name notebook -p 8888:8888 jupyter/datascience-notebook
- 起動したコンテナへ接続する
shell
docker exec -it notebook /bin/bash
- トークンを表示し、出力されたURLへブラウザからアクセスする。
shell
jupyter notebook list
-
アクセスしたブラウザにて、よしなにnwdiagを実行したいnotebookを作成する。(kernelはpython3を選択する)
-
コンソールに戻り、nwdiagをインストールする
shell
pip install nwdiag
- diagmagic.pyをgit cloneする
shell
git clone https://gist.github.com/a8e8269d4331b6b93e7ef90744fe0b3b.git
- 作成したnotebookのディレクトリ配下の.ipython/extensions/へdiagmagic.pyをコピーする。
shell
cp a8e8269d4331b6b93e7ef90744fe0b3b/diagmagic.py <notebookの格納ディレクトリ>/.ipython/extensions/