pythondlib

ImportError: libboost_python.so.1.65.1: cannot open shared object file: No such file or directory


First of all, I am using ARM7 architecture . I downloaded dlib library using pre-build wheel file dlib-19.7.0-cp27-cp27mu-linux_armv7l.whl and download Boost.python libraries and built them for python libraries, and when import dlib in python2.7 I got that error

>>> import dlib
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/lib/python2.7/dist-packages/dlib/__init__.py", line 1, in <module>
from .dlib import *
ImportError: libboost_python.so.1.65.1: cannot open shared object file: No such file or directory

Then I searched for libboost_python.so.1.65.1 in my directories and found it

:~# whereis libboost_python.so.1.65.1
libboost_python.so.1.65: /usr/local/lib/libboost_python.so.1.65.1

and found out that path (/usr/local/lib/) wasn't a part of PATH variable , so, I added it

:~# export PATH=$PATH:/usr/local/lib

and made sure that it placed correctly

:~# echo $PATH
/usr/local/sbin:/usr/local/bin:/usr/sbin:/usr/bin:/sbin:/bin:/usr/games:/usr/local/games:/usr/local/lib

and tried again but nothing, the same error appeared. I also installed libboost-all-dev using apt-get and make update after that but also the same error arise. So, what is the reason for that error and how can I overcome it ?

Thanks for advise.


Solution

  • I've got the same error. no need to install libboost-dev-all it's an overkill...

    You did not compile the libboost for python correctly. I've done the same but just with one flag --with-libraries=python and got exactly the same error.

    I knew my compiling was not good and a few trials got me to make this work.

    wget https://dl.bintray.com/boostorg/release/1.65.1/source/boost_1_65_1.tar.gz \
    && tar zxf boost_1_65_1.tar.gz \
    && cd boost_1_65_1 \
    && ./bootstrap.sh --with-libraries=python --with-python=python3.5 \
    && ./b2 install
    

    pay attention to the flag --with-python=python3.5 you will probably need to pass python2.7 instead

    here's how you can test it:

    import dlib
    import numpy as np
    image = np.arange(100*100*3).reshape(100, 100, 3)
    fd = dlib.get_frontal_face_detector()
    faces, scores, _ = fd.run(image, 0, 0)
    faces, scores, _ = fd.run(image, 0, -100)
    print(scores)
    
    -2.38875
    -2.77087
    -2.82851
    -2.84197
    -3.05489
    -3.0879
    

    if you get an error like this:

    >>> import dlib
    Traceback (most recent call last):
      File "<stdin>", line 1, in <module>
      File "/usr/local/lib/python3.5/dist-packages/dlib/__init__.py", line 1, in <module>
        from .dlib import *
    ImportError: libboost_python3.so.1.65.1: cannot open shared object file: No such file or directory
    

    make sure you add /usr/local/lib to the LD_LIBRARY_PATH

    export LD_LIBRARY_PATH=/usr/local/lib:$LD_LIBRARY_PATH