Error in import caffe

1,506 views
Skip to first unread message

hiarez...@gmail.com

unread,
Mar 6, 2016, 9:09:51 AM3/6/16
to Caffe Users
Hi to all,
  I recently have installed caffe on my ubuntu, and when I want to use python wrapper, get the "ImportError: No module named caffe" error:
>>> import caffe
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
ImportError: No module named caffe

when I added pythonpath, it solved and no error resulted but in the next time this error was repeated again.
Thank

Jan

unread,
Mar 6, 2016, 2:04:43 PM3/6/16
to Caffe Users
well, the PYTHONPATH is an environment variable, which resets if you close and re-open your shell. It is just in the nature of the thing. To (artificially) add it more permanently, you could add something along the lines of

export PYTHONPATH=/your/caffe/dir/python

to your .bashrc. Or, you just do something like
import sys
sys
.path.append('your/caffe/dir/python')

# and then import caffe
import caffe

in your python scripts that use caffe. The third option would be to really install (copy) the pycaffe package to your standard python directories. But I would not recommend that, it is inconvenient to have something installed there not maintained by your package manager, and you'd have to reinstall it there every time to pull and recompile caffe.

Jan

hiarez...@gmail.com

unread,
Mar 7, 2016, 5:24:09 AM3/7/16
to Caffe Users
Thanks Jan It worked well. 
Reply all
Reply to author
Forward
0 new messages