"import caffe " error in python and ipython -- undefined library symbols problem

3,237 views
Skip to first unread message

Thomas Hardman

unread,
Jul 12, 2015, 2:17:25 PM7/12/15
to caffe...@googlegroups.com
Greetings, all,

Built "caffe". Clone from git as of 2015 July 11. OpenCV installed via apt-get from Ubuntu (14.04) repository. Installed all 64-bit libboost packages (v. 1.54 current). Installed Anaconda3, current as of 2015 July 11. Installed CuDNN from NVidia repository, same date.

The Anaconda python3.4 binary is found first in $PATH, added PYTHONPATH to .bashrc including CAFFE_HOME. CAFFE_HOME is /usr/local/caffe-150712 with symlink to /usr/local/caffe. Added CuDNN, CUDA, etc to LD_LIBRARY_PATH.

"Caffe" builds, passes 'make test' and 'make runtest'. Completes 'make runtest' without error other than concluding "you have disabled two tests". Completes 'make pycaffe'. I copy all of build directory to /usr/local/caffe, using `cp build/* /usr/local/caffe`. `ldconfig -v` and all of this.

Now I try 'ipython' and then "import caffe" and also 'python' gives same results. Help please! Possibly some linker flag is needed to use boost_python properly?
Output follows, library is found, but symbols are unresolved.

In [1]: import caffe
---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-1-1cca3aa1f8c5> in <module>()
----> 1 import caffe

/usr/local/caffe-150712/python/caffe/__init__.py in <module>()
----> 1 from .pycaffe import Net, SGDSolver
      2 from ._caffe import set_mode_cpu, set_mode_gpu, set_device, Layer, get_solver
      3 from .proto.caffe_pb2 import TRAIN, TEST
      4 from .classifier import Classifier
      5 from .detector import Detector

/usr/local/caffe-150712/python/caffe/pycaffe.py in <module>()
     11 import numpy as np
     12
---> 13 from ._caffe import Net, SGDSolver
     14 import caffe.io
     15

ImportError: /usr/local/caffe-150712/python/caffe/_caffe.so: undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE



Thomas Hardman

unread,
Jul 12, 2015, 4:13:30 PM7/12/15
to caffe...@googlegroups.com
On Sunday, July 12, 2015 at 2:17:25 PM UTC-4, Thomas Hardman wrote:
Greetings, all,

<trimmed>
 
Now I try 'ipython' and then "import caffe" and also 'python' gives same results. Help please! Possibly some linker flag is needed to use boost_python properly?
Output follows, library is found, but symbols are unresolved.

In [1]: import caffe

<trimmed>
 
ImportError: /usr/local/caffe-150712/python/caffe/_caffe.so: undefined symbol: _ZN5boost6python6detail11init_moduleER11PyModuleDefPFvvE

 
Possibly solved.

Here is an issue that needs examination, anyway.

Because almost all configuration is done in Makefile.config I did not check the library calls in the Makefile.

A specific call is made from Makefile, for -lpython2.7 but I am using Anaconda3. Library call should be to -lpython3.4m. I have adjusted the Makefile and compilation is progressing. I will advise after completion and testing.

Thanks to
<a href="http://stackoverflow.com/questions/19865757/importerror-usr-lib-libboost-python-so-1-54-0-undefined-symbol-pyclass-type">this page on a similar matter</a>.

Thomas Hardman

unread,
Jul 13, 2015, 12:04:30 AM7/13/15
to caffe...@googlegroups.com

DISREGARD please, I abandoned using Anaconda and will use Python2.7. My apologies.




On Sunday, July 12, 2015 at 2:17:25 PM UTC-4, Thomas Hardman wrote:

T

unread,
Jul 13, 2015, 3:46:24 AM7/13/15
to caffe...@googlegroups.com
Hi Thomas. If you're using Debian this might help https://groups.google.com/forum/?utm_medium=email&utm_source=footer#!msg/caffe-users/n1fNZSrf_FU/2G-3AsiEDOEJ
It does pretty much everything.

Thomas Hardman

unread,
Jul 13, 2015, 11:47:55 AM7/13/15
to caffe...@googlegroups.com

Thank you very much! It looks very complete and will give me a lot of guidance for my Ubuntu build.

First I will try a very standard python2.7 build, and give that some testing. I'll try your method later, because I really would prefer to be using a more modern python version. Regards,

Alejandro Delgado

unread,
Jul 13, 2015, 4:38:29 PM7/13/15
to caffe...@googlegroups.com
hi,

you have to compile boost_python to python3.4 or use the "libboost-python1.55-dev" package using apt-get.

if you're building yourself 'boost' use --with-python = PYTHON
to indicate the path to the executable python3.4.
(in my case ~ / anaconda3 / envs / PY34 / bin / python3.4)

Then, when compiling caffe, be sure to change the path of the libraries and include python and libboost.

I use 'ccmake' to set up and these are the changes:

Boost_PYTHON-PY34_LIBRARY_DEBU   /usr/lib/x86_64-linux-gnu/libboost_python-py34.so
Boost_PYTHON-PY34_LIBRARY_RELE   /usr/lib/x86_64-linux-gnu/libboost_python-py34.so                                       
Boost_PYTHON-PY_LIBRARY_DEBUG    /usr/lib/x86_64-linux-gnu/libboost_python-py34.so                                       
Boost_PYTHON-PY_LIBRARY_RELEAS   /usr/lib/x86_64-linux-gnu/libboost_python-py34.so                                       
Boost_PYTHON_LIBRARY_DEBUG       /usr/lib/x86_64-linux-gnu/libboost_python-py34.so                                       
Boost_PYTHON_LIBRARY_RELEASE     /usr/lib/x86_64-linux-gnu/libboost_python-py34.so                                       
Boost_SYSTEM_LIBRARY_DEBUG       /usr/local/lib/libboost_system.so                                                       
Boost_SYSTEM_LIBRARY_RELEASE     /usr/local/lib/libboost_system.so                                                       
Boost_THREAD_LIBRARY_DEBUG       /usr/local/lib/libboost_thread.so                                                       
Boost_THREAD_LIBRARY_RELEASE     /usr/local/lib/libboost_thread.so

PYTHON_EXECUTABLE      ~/anaconda3/envs/py34/bin/python3.4                                             
PYTHON_INCLUDE_DIR     ~/anaconda3/envs/py34/include/python3.4m                                        
PYTHON_LIBRARY         ~/anaconda3/envs/py34/lib/libpython3.so

python_version         3.4
when you change this variable you have to comment the line 103 in file Dependencies.cmake in folder cmake
STRING (REPLACE "." "" Boost_py_version $ {version})
to avoid problems.

this works for me, I hope this will work well for you. greetings

Thomas Hardman

unread,
Jul 13, 2015, 8:54:27 PM7/13/15
to caffe...@googlegroups.com

Thank you for this.

I tried almost the exact same thing, building libboost_python1.55 against the Anaconda python installation.

After several attempts to build, all of which attempts seemed successful, when I attempt to run dream.ipynb with cut-and-paste one line at a time, from "import caffe" I get "unspecified unhandled error", or very similar message.

I will try this again. I omitted one step in the compilation/installation process for 'caffe'. On the "installing caffe" page, there is no instruction to "make distribute". I did not do that "make distribute", I did not know about it.

The version I have built with the standard Ubuntu libboost_python1.54 and python2.7 has built, and seems to almost work, trying to use 'ipython notebook dream.ipynb' does start a browser window with the README.md interspersed with chunks of code, but attempting to "run" under the menu "cell" produces some error of "unexpected keyword syntax."

I will try to rebuild using these helpful posts, above, thank you all very much.
Reply all
Reply to author
Forward
0 new messages