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?

  • Are you aware that (at least by default) python is python2 on Ubuntu 14.04? Are you trying to import dlib from python or from python3? Sep 14, 2016 at 14:16
  • Sure, I tried both python2 and python3, but still no effect
    – wasd
    Sep 14, 2016 at 14:19
  • @wasd You said you are trying to run it from a virtualenv? Then you can just activate the virtualenv and use pip to install dlib. Or if yo have dlib installed globally, you can create a virtualenv with the --system-site-packages option.
    – edwinksl
    Sep 14, 2016 at 18:13
  • @edwinksl If I try to install dlib with pip it gives CMake Error at /usr/share/cmake-2.8/Modules/FindPackageHandleStandardArgs.cmake:108 (message): Could NOT find PythonLibs (missing: PYTHON_LIBRARIES) (Required is at least version "3.4")
    – wasd
    Sep 15, 2016 at 12:10

1 Answer 1


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.

  • 1
    Awesome, I hadn't noticed cmake was only at version 2.8 in Ubuntu 14.04.
    – edwinksl
    Sep 15, 2016 at 17:33

You must log in to answer this question.

Not the answer you're looking for? Browse other questions tagged .