No module found

KAIYUAN ZHNAG picture KAIYUAN ZHNAG · Nov 29, 2017 · Viewed 9.6k times · Source

I install caffe and it worked fine. In cmd, I can import it use python, but when I use jupyter notebook, I can't import it.

enter image description here

enter image description here

How can I solve it?

Answer

Simon Bowly picture Simon Bowly · Nov 29, 2017

It looks like you have put /home/mltitan/Workspace/caffepython in the path instead of /home/mltitan/Workspace/caffe/python which may have been your intention.

Adding the strings together as you have done will not insert the slash in the path. Best practise is to use os.path.join to handle this:

import os
import sys

caffe_root = '/home/mltitan/Workspace/caffe'
sys.path.insert(0, os.path.join(caffe_root, 'python'))
import caffe

Does that help?