シェルでは使えているPythonモジュールをJupyterNotebookで実行すると「ImportError: No module named module_name」が出てくる
問題点
はじめてPytorchを使った際に以下のようなエラーが。
ImportError: No module named torch
pip installする
$ pip install torch Requirement already satisfied: torch in /home/ubuntu/miniconda3/lib/python3.6/site-packages (0.4.1)
既にインストールされてる。
シェルでも問題なく使える
$ python Python 3.6.5 |Anaconda, Inc.| (default, Apr 29 2018, 16:14:56) [GCC 7.2.0] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import torch >>>
はて…?
現状
現在はvenvで作った環境にいる。
$ conda create -n pytorch-segmentation-detection $ source activate pytorch-segmentation-detection (pytorch-segmentation-detection) ubuntu@ip-172-31-5-82:~/Code/pytorch-segmentation-detection$
が、Jupyter上で見るとこの「pytorch-segmentation-detection」というカーネルが存在しない。
解決策
そこで、ipykernelをインストールする。
$ conda install ipykernel $ ipython kernel install --user --name pytorch-segmentation-detection --display-name pytorch-segmentation-detection
出てきた!