[Question about installing Caffe]from caffe import layers error: ImportError: cannot import name 'la

576 views
Skip to first unread message

BK Zero

unread,
Apr 26, 2016, 11:36:54 AM4/26/16
to Caffe Users
I successfully go through the whole steps in installing caffe, and the final two are: 
make
make pycaffe
and when i enter anaconda3.5, i can also run 
import caffe
successfully.
but when i run 
from caffe import layers
i got the error message 
ImportError: cannot import name 'layers'
so i check the module by 
dir(caffe)
to see whether it has the class member named 'layers'. but being surprised, i got only
['__doc__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
it is werid!!!
it seems like my caffe is not completed install or the python can not find it correctly.
so how can i fix the problem? does this mean i ''make pycaffe'' successfully? 
i didn't install the opencv, but l did "sudo apt-get install libopencv-dev", does it matter?
or did i make some mistake when i export the pythonpath by "export PYTHONPATH=/home/zero/Documents/caffe-master/build/python:$PYTHONPATH"?
and then, someone writes they run ''make runtest'' after make test, but when i did this, i got
~/Documents/caffe-master$ sudo make runtest [sudo] password for zero:.build_release/tools/caffe .build_release/tools/caffe: error while loading shared libraries: libboost_system.so.1.55.0: cannot open shared object file: No such file or directory make: *** [runtest] Error 127 
i don't know whether it is a reason of import error

BK Zero

unread,
Apr 26, 2016, 8:59:55 PM4/26/16
to Caffe Users
anyone can help?

在 2016年4月26日星期二 UTC+8下午11:36:54,BK Zero写道:

Jan

unread,
Apr 27, 2016, 5:26:24 AM4/27/16
to Caffe Users
Well, yes, apparently pycaffe did not compile successfully. There should be more in the caffe python package. "make pycaffe" should have given you an error message, what is it? Are you using the cmake build or the plain make build?

i didn't install the opencv, but l did "sudo apt-get install libopencv-dev", does it matter?


In the same sentence you are saying you didn't install it and that you installed it. That doesn't make any sense to me...

The PYTHONPATH is ok.

And the last error message is indeed an indication that there is something wrong. Did you install boost (e.g. apt-get install libboost1.55-all-dev or just libboost-all-dev)? Make sure you have only one version of boost on your system (1.55 or 1.54), this will prevent a lot of headaches.

And one last thing: You shouldn't need to use sudo to do anything with caffe (neither in compilation nor in running). If you do, you are probably doing something wrong.

Jan

BK Zero

unread,
Apr 27, 2016, 7:37:13 AM4/27/16
to Caffe Users
thanks for your replies!
firstly, i use make, not the cmake.
and then, some hints is teaching how to install opencv by hand, and they also install it by apt-get, i just install it by apt-get, i am not sure whether there is any difference between the two ways. you just mean it is ok to install it only by apt-get?
in the morning, i try some different PYTHONPATH, and the result is quite different. now i am confused which path should set.
i install the boost by apt-get libboost-all-dev, and somehow it indicates that it is ver1.54, and the caffe website says boost should >=1.55, so i install a 1.55 version by hand(what i mean by hand is i download the zips, and compile it, then install by command "sudo ./b2 install", not by apt-get).
and i may use the sudo when i make.
thanks for you advices. one more last question. when i trying to uninstall the boost1.54, shell gives this message
"
The following packages were automatically installed and are no longer required:
libboost-chrono1.54.0 libboost-context-dev libboost-context1.54-dev
...
Use 'apt-get autoremove' to remove them.

should i remove them? if i do, will it cause some problem? most of them are in version1.54.

在 2016年4月27日星期三 UTC+8下午5:26:24,Jan写道:

Jan

unread,
Apr 27, 2016, 8:20:36 AM4/27/16
to Caffe Users
In general I'd recommend to install packages through apt-get. Only install from source if there is no other way*. The problem is, that it is easy to mess up your system by fiddling in apt-get installed files manually. On the other hand, I recommend to have only one version of a library installed, because otherwise there might and will be version clashes which can lead to strange errors if the binaries are using the wrong version of a library, or a different version rt runtime than at compile time. And to prevent this, extreme care needs to be taken, BOTH at compile time and runtime. And it is even harder to get it right for relative beginner in linux development (I don't know your experience level, just saying ;-) ).

If you use boost only for caffe, then it should be no problem to just remove the 1.54 libs and install the 1.55 via apt-get. They are not tied into the operating system or anything. Actually, in the case of boost it should be even safe to install both versions, as long as you do it with apt-get (of course it is also possible from source, but harder to get it right). When you do apt-get remove libboost1.54-all-dev you'll see if there are other packages depending on boost 1.54, because apt-get threatens to also remove these.

* meaning you need a version of the lib not (yet) present in the apt repos, or (happends more rarely) a version compiled with different settings.

Jan

BK Zero

unread,
Apr 27, 2016, 8:31:48 AM4/27/16
to Caffe Users
thanks for your advice again. i will try to re-install it from the beginning. or maybe i should try the 2.7version.
i am a really beginner in linux, so it makes me headache for over one week. hope i will fix it tonight. thanks a lot.

在 2016年4月27日星期三 UTC+8下午8:20:36,Jan写道:
Reply all
Reply to author
Forward
0 new messages