I cannot "import caffe" in my python interactive shell. The error message is:
>>>import caffe
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named caffe
I performed "make pycaffe" in /caffe/ folder after "make all" and check all the dependencies. The ubuntu version is 14.04, python 2.7.6 .
In addition, if I tried to "import _caffe.so" the error message is:
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: libcudart.so.6.0: cannot open shared object file: No such file or directory
Thanks!
pls import caffe in $CAFFE/python or add the path to sys.path
@shuokay Could you please advise me more detailed steps? Thanks!
https://www.google.com.hk/webhp?sourceid=chrome-instant&ion=1&espv=2&ie=UTF-8#ie=UTF-8&q=python%20how%20to%20add%20the%20path%20to%20sys.path&sourceid=chrome-psyapi2
@shuokay Thank you! The method at http://www.johnny-lin.com/cdat_tips/tips_pylang/path.html works.
Also, in Ubuntu, the python wrapper can be added into the PYTHONPATH in the file ".bashrc" at /home .
export PYTHONPATH=/home/username/caffe/python
@luzhi Thanks for your answer
@luzhi should I type, every timy I open the python console:
export PYTHONPATH=/home/username/caffe/python
from home ?
(sorry I'm a bit confused)
@attiliotnt
luzhi said add this line in your ".bashrc" file which is located at "/home".
That way, terminal will run this line every time you open it ! So, no, you don't have to run it every time.
i got the same error! anyone has solved this please give us the point. i compiled and set path correctly but still it give me no caffe module found
@sayadyaghoobi
I am hoping you are compiling caffe twice (i.e. once in the main repository and the other time in the recursively imported repository) and then posting the problems ?
Also, the PYTHONPATH exported would be better as:
export PYTHONPATH=/complete/path/to/caffe/python:$PYTHONPATH
in either your ~/.bashrc or ~/.bash_profile.
(The $PYTHONPATH also appends everything else in the new PYTHONPATH)
caffe_root = '../../../caffe-master/' (This is the path of caffe-master)
import sys
sys.path.insert(0, caffe_root + 'python')
import caffe
you should add above lines in the script.
Okay, I ran in the same Problem.
I tried to import chainer and use caffe
I found a solution here: https://teratail.com/questions/82964
So do this in top of your code:
import chainer
import chainer.links
from chainer.links import caffe
The original code was :
import chainer
import chainer.functions as F
from chainer.functions import caffe
Please also import functions as F so the code will work as it was intended
Most helpful comment
@shuokay Thank you! The method at http://www.johnny-lin.com/cdat_tips/tips_pylang/path.html works.