Ubuntu – How to install dlib for python3 in Ubuntu 14.04

ccmakecompilingpythonsoftware installation

I'm following this guide https://cmusatyalab.github.io/openface/setup/ of installation. I did:

 mkdir -p ~/src
 cd ~/src
 tar xf dlib-19.1.0.tar.gz
 cd dlib-19.1.0/python_examples
 mkdir build
 cd build
 cmake ../../tools/python
 cmake --build . --config Release
 sudo cp dlib.so /usr/local/lib/python3.4/dist-packages/

It says that at this point I should be able to run import dlib, but if I run it from virtualenv gives me

ImportError: No module named dlib

If I run it outside from virtualenv it gives:

ImportError: dynamic module does not define init function (PyInit_dlib)

What am I doing wrong? How to install dlib for python?

UPD: I've tried same for Python2:

sudo cp dlib.so /usr/local/lib/python2.7/dist-packages/

and it worked for python2. So how to do the same for python3?

Best Answer

Found solution by myself but thanks @edwinksl for his tip. In order to install dlib for python3 it's better to use pip:

pip install dlib

You will need boost python. To get it:

sudo apt-get install libboost-all-dev

If you have "Could NOT find PythonLibs (missing: PYTHON_LIBRARIES) (Required is at least version "3.4")" error make sure you have cmake > 2.8 (In my case it is 3.2.2). To install cmake > 2.8:

sudo add-apt-repository ppa:george-edison55/cmake-3.x
sudo apt-get update
sudo apt-get install cmake

That solved the issue for me.

Related Question