Dlib: import error

Created on 18 Oct 2017  路  10Comments  路  Source: davisking/dlib

  1. python 3.6
  2. dlib 19.7
  3. Mac OS

When import dlib:

import dlib
Traceback (most recent call last):
  File "<input>", line 1, in <module>
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
  File "/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/dlib-19.7.99-py3.6-macosx-10.6-intel.egg/dlib/__init__.py", line 1, in <module>
    from .dlib import *
  File "/Applications/PyCharm CE.app/Contents/helpers/pydev/_pydev_bundle/pydev_import_hook.py", line 21, in do_import
    module = self._system_import(name, *args, **kwargs)
ImportError: dlopen(/Library/Frameworks/Python.framework/Versions/3.6/lib/python3.6/site-packages/dlib-19.7.99-py3.6-macosx-10.6-intel.egg/dlib/dlib.so, 2): Symbol not found: _PyClass_Type
  Referenced from: /usr/local/opt/boost-python/lib/libboost_python-mt.dylib
  Expected in: flat namespace
 in /usr/local/opt/boost-python/lib/libboost_python-mt.dylib

Any help?

good question

Most helpful comment

  1. uninstall boost-python for python2
    brew uninstall boost-python
  2. install boost-python for python3
    brew install boost-python --with-python3
  3. change name of libboost_python3 to libboost_python
    cd /usr/local/opt/boost-python/lib/
    ls, and got something like this:
libboost_python-mt.a            libboost_python3-mt.a
libboost_python-mt.dylib        libboost_python3-mt.dylib
libboost_python.a               libboost_python3.a
libboost_python.dylib           libboost_python3.dylib

backup boost-python for python2 and change boost-python for python3:

mv libboost_python-mt.a libboost_python2-mt.a && cp libboost_python3-mt.a libboost_python-mt.a
mv libboost_python-mt.dylib libboost_python2-mt.dylib && cp libboost_python3-mt.dylib libboost_python-mt.dylib
mv libboost_python.a libboost_python2.a && cp libboost_python3.a libboost_python.a
mv libboost_python.dylib libboost_python2.dylib && cp libboost_python3-mt.dylib libboost_python.dylib
  1. clone dlib from github and cd dlib
    python3 setup.py install --yes USE_AVX_INSTRUCTIONS

Done!

All 10 comments

Yes, I have more than one copy of Python installed on my Mac and they are

  1. /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6
  2. /System/Library/Frameworks/Python.framework/Versions/2.6/bin/python2.6
  3. /System/Library/Frameworks/Python.framework/Versions/2.7/bin/python2.7
  4. /usr/bin/python
  5. ~/anaconda/envs/py35/bin/python
  6. ~/anaconda/envs/py27/bin/python

I pip3 install dlib for python3.6. So, how should I complie Boost and dlib against python 3.6?

Run dlib's setup.py script with the python you want to use. As for boost,
I don't know. I would refer to the boost documentation for instructions in
your case.

I brew install boost-python --with-python3 and run python3 setup.py install --yes USE_AVX_INSTRUCTIONS. But same error when import dlib. I think I should try some other way of installing boost-python.

stackoverflow solution to correct boost-python error.

  1. uninstall boost-python for python2
    brew uninstall boost-python
  2. install boost-python for python3
    brew install boost-python --with-python3
  3. change name of libboost_python3 to libboost_python
    cd /usr/local/opt/boost-python/lib/
    ls, and got something like this:
libboost_python-mt.a            libboost_python3-mt.a
libboost_python-mt.dylib        libboost_python3-mt.dylib
libboost_python.a               libboost_python3.a
libboost_python.dylib           libboost_python3.dylib

backup boost-python for python2 and change boost-python for python3:

mv libboost_python-mt.a libboost_python2-mt.a && cp libboost_python3-mt.a libboost_python-mt.a
mv libboost_python-mt.dylib libboost_python2-mt.dylib && cp libboost_python3-mt.dylib libboost_python-mt.dylib
mv libboost_python.a libboost_python2.a && cp libboost_python3.a libboost_python.a
mv libboost_python.dylib libboost_python2.dylib && cp libboost_python3-mt.dylib libboost_python.dylib
  1. clone dlib from github and cd dlib
    python3 setup.py install --yes USE_AVX_INSTRUCTIONS

Done!

Sweet, thanks for reporting how to fix it :)

Thank you for the instructions! Slight typo though (needs double ampersand not single, otherwise it gets confused and tries to create daemons!)

mv libboost_python-mt.a libboost_python2-mt.a && cp libboost_python3-mt.a libboost_python-mt.a
mv libboost_python-mt.dylib libboost_python2-mt.dylib && cp libboost_python3-mt.dylib libboost_python-mt.dylib
mv libboost_python.a libboost_python2.a && cp libboost_python3.a libboost_python.a
mv libboost_python.dylib libboost_python2.dylib && cp libboost_python3-mt.dylib libboost_python.dylib

I found that using an older version of boost on macOS fixed things for me:

brew install homebrew/versions/boost155

The @Aspirinkb 's solution are not work at all. Still same error after do this.

Was this page helpful?
0 / 5 - 0 ratings