Installing dlib

Dlib (http://dlib.net/python/index.html) is a C++ software library that contains computer vision, machine learning, and deep learning algorithms. Dlib can also be used in your Python applications. In order to install dlib with the Python interface (https://pypi.org/project/dlib/), use the following command:

$ pip install dlib

Alternatively, if you want to compile dlib yourself, go into the dlib root folder and run the following command:

$ python setup.py install

Once that command has finished running, you are ready to use dlib from Python.

Note that you need to have both CMake and a C++ compiler installed for this to work properly. Also note that various optional features, such as GUI support (for example, dlib.image_window) and CUDA acceleration, will be either enabled or disabled based on what is available on your computer. 

A third option for installing dlib is to access http://pypi.fcio.net/simple/dlib/ and install the required dlib wheel package. In my case, I have downloaded the dlib-19.8.1-cp36-cp36m-win_amd64.whl file and installed it with the following command:

$ pip install dlib-19.8.1-cp36-cp36m-win_amd64.whl

The wheel filename is {distribution}-{version}(-{build tag})?-{python tag}-{abi tag}-{platform tag}.whl. For example, distribution-1.0-1-py27-none-any.whl is the first build of a package called distribution, and it is compatible with Python 2.7 (any Python 2.7 implementation), with no ABI (pure Python), on any CPU architecture. See https://www.python.org/dev/peps/pep-0427/ for further details about the wheel binary package format.

To confirm that the installation has been performed correctly, just open a Python shell and try to import the dlib library:

python
import dlib
Remember that a recommended approach is to install packages in virtual environments. See Chapter 1Setting Up OpenCV, for information on how to create and manage virtual environments.

For example, in this case, we will install dlib in a virtual environment using Anaconda Prompt:

  1. Create a virtual environment:
(base) $ conda create -n dlib-env python=3.6
  1. Activate the environment:
(base) $ activate dlib-env

See how (dlib-env) appears before the prompt after this command. This indicates that the virtual environment has been activated.

  1. Install dlib using the following commands:
(dlib-env) $ pip install dlib