2017-10-05 3 views
0

コマンドラインで実行しようとしているpython jupyterノートブックがあります。ここではコマンドです:ジュピターノートブックを実行しているときにインポートエラーを修正するにはどうすればよいですか?

jupyter nbconvert --to notebook --execute --ExecutePreprocessor.timeout=60 --output out_file test.ipynb 

そして、ここでは、このノートPCのテストバージョンである(test.ipynb

次のコードに対応
{"cells":[{"metadata":{"deletable":true,"editable":true},"cell_type":"markdown","source":["# Morphology analysis with neurom\n","\n","You can find the full documentation of neurom on http://neurom.readthedocs.io/en/latest/index.html ."]},{"metadata":{"collapsed":false,"deletable":true,"editable":true,"trusted":false},"cell_type":"code","source":["%matplotlib inline\n","from copy import deepcopy\n","\n","from IPython.display import display, HTML\n","import urllib, zipfile, os\n","\n","try:\n"," import neurom\n"," from neurom import viewer, stats\n","except ImportError:\n"," !pip2 install neurom\n"," import neurom\n"," from neurom import viewer, stats"],"execution_count":null,"outputs":[]}],"metadata":{"kernelspec":{"name":"python2","display_name":"Python 2","language":"python"},"language_info":{"version":"2.7.6","mimetype":"text/x-python","file_extension":".py","codemirror_mode":{"version":2,"name":"ipython"},"nbconvert_exporter":"python","name":"python","pygments_lexer":"ipython2"}},"nbformat":4,"nbformat_minor":2} 

でこのコードを実行する
get_ipython().magic(u'matplotlib inline') 
from copy import deepcopy 

from IPython.display import display, HTML 
import urllib, zipfile, os 

try: 
    import neurom 
    from neurom import viewer, stats 
except ImportError: 
    get_ipython().system(u'pip2 install neurom') 
    import neurom 
    from neurom import viewer, stats 

上記のコマンドを実行すると、次のエラーが表示されます。

ImportError: No module named neurom 
このモジュールは現在の設定にインストールされていますが、

です。だから、なぜこのモジュールをピックアップしていないのですか?

答えて

0

ノートブックの実行で現在の環境(例:virtualenv)が使用されておらず、jupyterノートブックに「追加」する必要があるようです。

だからまず、あなたは通常、ファイル~/.jupyter/jupyter_notebook_config.pyを生成し、このコマンド

jupyter notebook --generate-config 

を使用して、標準の設定を生成します。このファイルには、次の部分を追加する必要があります。

c.InteractiveShellApp.exec_lines=[ 
    'import sys; sys.path.append("path-to-add")' 
] 

実行にパスを追加する必要があります。

また、スレッドhereも参照してください。

関連する問題