Dlib python install windows

June 12, 2017 By 45 Comments

In this post, we will provide step by step instructions on how to install Dlib on Windows.

Compiling Python modules such as NumPy, SciPy etc. is a tedious task. Anaconda is a great Python distribution which comes with a lot of pre-compiled Python packages. So we will use Anaconda as our Python distribution.

An alternative to Anaconda is that you install official Python library and use Christoph Gohlke’s awesome repository to install pre-compiled Python modules.

This tutorial is based on using Anaconda so we may not be able to help if you choose to use Gohlke’s precompiled binaries or if you compile Python libraries from source.

If you intend to use Dlib only in C++ projects, you can skip Python installation part.

Now let’s go through the steps to install Dlib. Follow our previous post Install OpenCV3 on Windows to complete Step 1, 2 and 3.

Step 1: Install Visual Studio 2015

Step 2: Install CMake v3.8.2

Step 3: Install Anaconda 3

Step 4: Download Dlib

Step 5: Build Dlib library

Extract this compressed file. Open Windows PowerShell or Command Prompt and move to the directory where you have extracted this file.

If you are running these commands on Command Prompt replace ` (backtick) with ^ (caret).

Dlib will be installed within dlib-19.6uildinstall directory. We will use CMake to build Dlib examples but you can use Visual Studio too. This directory (dlib-19.6uildinstall) contains include and library folders which you can specify in Visual Studio to build projects using Dlib.

Step 6: Update user environment variable – dlib_DIR

This environment variable is needed for CMake to find out where Dlib is installed. CMake looks for a file named dlibConfig.cmake within directory dlib_DIR to find Dlib’s include and library directories.

  1. Press Windows Super key, search for “environment variables”.
  2. Click Environment Variables in System Properties window.
  3. Click New in “User Variables” (in upper half of window).
  4. Under variable name write dlib_DIR and under variable value write full path to directory dlib-19.6uildinstalllibcmakedlib
    On my machine path is: D:programmingdlib-19.6uildinstalllibcmakedlib
    This directory contains file “dlibConfig.cmake”. This is used by CMake to configure dlib_LIBS and dlib_INCLUDE_DIRS variables to generate project files. Before assigning the value to variable dlib_DIR make sure that this path has file dlibConfig.cmake.
  5. Now click ok to save and close environment variables window.

Note: If you have an open Command Prompt/Power Shell window before these values were updated, you have to close and open a new Command Prompt/Power Shell window again.

Step 7: Build Dlib examples

We will use our CMakeLists.txt file instead of one which is shipped with Dlib.
Download modified CMakeLists.txt file and put it in dlib-19.6examples directory and replace the default one with this one. Then follow the steps given below:

Once build is complete, it will generate executables for all examples in examplesuildRelease folder.

Step 8: Test Dlib’s C++ example

We will test Face Landmark Detection demo to check whether we have installed Dlib correctly.
Download trained model of facial landmarks from Dlib’s website. Extract this file (shape_predictor_68_face_landmarks.dat.bz2) to Dlib’s root directory (dlib-19.6).

Step 9: Install Dlib’s Python module (Only Anaconda 3)

Compiling Python bindings for Dlib from source is non-trivial. You have to compile Boost.Python from scratch and configure some environment variables (such as BOOST_ROOT and BOOST_LIBRARYDIR) before you can compile Python module of Dlib. We are skipping that part for now. A complete tutorial on how to build Dlib Python bindings from source will be released in future.

To save time and efforts it is suggested to use Anaconda 3. You can install a compiled binary of dlib v19.4 from Anaconda. At the time this article was updated Dlib’s latest available version on Anaconda’s conda-forge repository is 19.4. So we will install v19.4 instead of 19.6

Step 10: Test Dlib’s Python example

Subscribe & Download Code

If you liked this article and would like to download code (C++ and Python) and example images used in all posts in this blog, please subscribe to our newsletter. You will also receive a free Computer Vision Resource Guide. In our newsletter, we share OpenCV tutorials and examples written in C++/Python, and Computer Vision and Machine Learning algorithms and news.

Easy Installation of dlib python in Windows

Bored of trying to compile things manually in Windows? Bored of downloading 12GB of Visual Studio just to get a decent windows C compatible compiler? I know :/

I know how complicated/annoying it is to compile dlib, then compile Boost (with python bindings) and then compile it again to get the python api. I lost valuable hours trying to do that and at the end it didnt compile for python because it didnt recognize my Boost installation!!

The easy way: Just dowload from this page (version 18.17) or this link (newer versions of dlib) the Python Wheel file and just pip install it ->

For python 2.7 and win32 just download this file and pip install it .

In this video we will see how to install the Dlib library for Python 3 on Windows.

In this specific tutorial we are going to install Dlib 19.8 for Python 3.6 (64 bit version). We choosed this specific version as it’s the latest one (March 2019 the moment I’m writing this post) which has ready binaries for windows.
In other words is the one that is really easy to install.

In this website you find all the binaries available at the moment:
https://pypi.org/simple/dlib/

If you don’t have Python and Opencv installed yet, go first with Python and Opencv installation following this tutorial.

Install Dlib for Python 3.6:

  1. Python 3.6 (64 bit) has to be already installed.
  2. Run Windows Prompt Command. You can type on the search bar “CMD”.

    Remember to click with right button of the mouse and then “Run it as administrator”, otherwise you might not have the permission to install the library.
  3. Type on the prompt command:
  4. Once you see the message “Successfully installed dlib“, it means that the installation has been completed.

You can now run Python, try importing the dlib library. If you don’t get any error, it means that the installation was done correctly.

Оцените статью
Много толка
Добавить комментарий