Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to get Python import working with dlib (using cmake and osx)

Tags:

python

cmake

dlib

Sorry if this is basic but I'm trying to install dlib to use with python as mentioned in (http://blog.dlib.net/2014/04/dlib-187-released-make-your-own-object.html) "Make your own object detector in Python!".

I downloaded the install files, unzipped, and used cmake as in the install instructions (http://dlib.net/compile.html)

cd examples
mkdir build
cd build
cmake ..
cmake --build . --config Release

which seemed to work fine

However typing "import dlib" in Python just gives ImportError: No module named dlib.

Any idea how I tell Python how to find / use the thing?

like image 245
Tim 333 Avatar asked May 05 '15 00:05

Tim 333


People also ask

How long does it take for dlib to install?

It may take a while to build wheel for dlib, after a while, it will be successfully installed. ... 10 mins for that "building wheel loop" to end and then it was installed successfully! Would advise to first wait for 10-15 minutes at least, before trying other answers given above.


2 Answers

Just a note for reference that the easiest way to install is now to use:

sudo python setup.py install
like image 131
liezlp Avatar answered Sep 27 '22 21:09

liezlp


Instead of manual file editing, you can pass -DPYTHON_LIBRARY:FILEPATH=/path/to/your/libpython2.7.dylib to cmake.

What ./compile_dlib_python_module.bat does is

mkdir build
cd build
cmake ../../tools/python

So, just run the commands by one by one and instead of

cmake ../../tools/python

run

cmake ../../tools/python -DPYTHON_LIBRARY:FILEPATH=/usr/local/Cellar/python/2.7.8/Frameworks/Python.framework/Versions/2.7/lib/libpython2.7.dylib
like image 43
Maciek Strömich Avatar answered Sep 27 '22 21:09

Maciek Strömich