59

I want to use dlib with python for image recognition. I have the python app running great with OpenCV on Windows 10, but when I want to install dlib from the cmd it gives me this following error :

error: Cannot find cmake, ensure it is installed and in the path. You
can install cmake using the instructions at https://cmake.org/install/
You can also specify its path with --cmake parameter.

What should I do?

My command prompt error

1
  • 11
    edit your question to include the actual error instead of just attaching a screenshot. This will make it easier to answer your question and will make your question useful to others with similar problems as well. Jan 28, 2017 at 17:52

19 Answers 19

93

Install Dlib from .whl (old, see next paragraph)

Dlib 19.7.0

pip install https://pypi.python.org/packages/da/06/bd3e241c4eb0a662914b3b4875fc52dd176a9db0d4a2c915ac2ad8800e9e/dlib-19.7.0-cp36-cp36m-win_amd64.whl#md5=b7330a5b2d46420343fbed5df69e6a3f

You can test it, downloading an example from the site, for example SVM_Binary_Classifier.py and running it on your machine.

Note: if this message occurs you have to build dlib from source:

dlib-19.7.0-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform


Install Dlib from source (If the solution above doesn't work)

Windows

Dlib > 19.7.0

  1. Download the CMake installer and install it: https://cmake.org/download/

  2. Add CMake executable path to the Enviroment Variables:

    set PATH="%PATH%;C:\Program Files\CMake\bin"

    note: The path of the executable could be different from C:\Program Files\CMake\bin, just set the PATH accordingly.

    note: The path will be set temporarily, to make the change permanent you have to set it in the “Advanced system settings” → “Environment Variables” tab.

  3. Restart The Cmd or PowerShell window for changes to take effect.

  4. Download the Dlib source(.tar.gz) from the Python Package Index : https://pypi.org/project/dlib/#files extract it and enter into the folder.

  5. Check the Python version: python -V. This is my output: Python 3.7.2 so I'm installing it for Python3.x and not for Python2.x

note: You can install it for both Python 2 and Python 3, if you have set different variables for different binaries i.e: python2 -V, python3 -V

note: You may need to open the PowerShell as admin before proceeding to step 6


  1. Run the installation: python setup.py install

Linux

Dlib 19.17.0

sudo apt-get install cmake

wget https://files.pythonhosted.org/packages/05/57/e8a8caa3c89a27f80bc78da39c423e2553f482a3705adc619176a3a24b36/dlib-19.17.0.tar.gz

tar -xvzf dlib-19.17.0.tar.gz

cd dlib-19.17.0/

sudo python3 setup.py install

note: To install Dlib for Python 2.x use python instead of python3 you can check your python version via python -V

9
  • 11
    dlib-19.7.0-cp36-cp36m-win_amd64.whl is not a supported wheel on this platform. Dec 1, 2018 at 9:25
  • 1
    Even if you have CMake installed, on windows you will have problems with the generator of CMake which is by default set to Nmake. Mar 22, 2019 at 12:37
  • 2
    Thanks, but I need to add something obvious! In order to build this for Python, make sure you have C++ compiler on your system!
    – Hossein
    Jan 16, 2020 at 5:18
  • 2
    I am getting this ` You must use Visual Studio to build a python extension on windows. If you are getting this error it means you have not installed Visual C++. Note that there are many flavors of Visual Studio, like Visual Studio for C# development. You need to install Visual Studio for C++.` is it necessary to install? Sep 2, 2020 at 15:41
  • 1
    @FAHADSIDDIQUI, it is indeed needed. After installing I receive a new error: No CMAKE_CXX_COMPILER could be found
    – DaReal
    Dec 12, 2021 at 21:42
72

Follow these steps:

  • pip install cmake
  • Install Visual Studio build tools from here.
  • In Visual Studio 2017 go to the Individual Components tab, Visual C++ Tools for Cmake, and check the checkbox under the "Compilers, build tools and runtimes" section.
  • pip install dlib
5
  • 3
    i tried most of the ways here and dlib still doesn't seems to work
    – Eshaka
    Sep 16, 2019 at 6:01
  • 1
    yes it works, to confirm, if your message is of kind "is not a supported on this platform", so be sure to install Visual C++ Tools for Cmake from visual studio installer ==> Individual Components tab
    – Y.AL
    Jul 9, 2020 at 8:02
  • when following these steps, I run into a new error No CMAKE_C_COMPILER could be found.
    – DaReal
    Dec 12, 2021 at 21:35
  • Wooow it's like 5GB of installation which is a bit frustrating
    – Ice Bear
    May 12 at 7:45
  • this works well! even with that kind of installation, I guess it's because the algo is that big
    – Ice Bear
    May 12 at 11:30
16

Effective till now(2020).

pip install cmake
conda install -c conda-forge dlib
1
  • via conda , which python version u used for this ??
    – django
    Oct 14, 2020 at 7:51
9

If you are using Anaconda Prompt (recommended),

conda install -c conda-forge dlib

Or you can use the approach mentioned below:

After spending a lot of time, this comment gave me the right result. https://github.com/ageitgey/face_recognition/issues/802#issuecomment-544232494

  1. Download Python 3.6.8 and install, make sure you add it to PATH.

  2. Install NumPy, scipy, matplotlib and pandas in your pc/laptop with this command in command prompt:-

    pip install numpy

    pip install scipy

    pip install matplotlib

    pip install pandas

  3. Go to https://pypi.org/project/wheel/#files and right-click on filename wheel-0.33.6-py2.py3-none-any.whl (21.6 kB) and copy link address. Then go to your pc/laptop, open command prompt and write this command "python -m pip install" after this command space first then paste the link copied. After installing successful go to the next step.

  4. Then go to this link, https://pypi.org/simple/dlib/ and right-click on filename "dlib-19.8.1-cp36-cp36m-win_amd64.whl" then copy link address. Then open command prompt and do the same as step 2 which is, write this command "python -m pip install" after this command space first then paste the link copied. then the dlib will be installed successfully.

  5. After that, type python and enter, then type import dlib to check dlib is installed perfectly. you can proceed to install face recognition.py which suite for python 3.6.

This is how it will be after dlib and face recognition installed.

0
6

As you can see many answers above, But i would like to post a quick solution which works for sure in Anaconda3. I haven't chosen Visual Studio as it consumes lot of memory.

Please follow the below steps.

Step 1:
Install windows cmake.msi and configure environment variable
Step 2:
Create a conda environment, and install cmake using the below command.
pip install cmake
Step 3:
conda install -c conda-forge dlib

Note you can find few other dlib packages, but the above one will works perfectly with this procedure.

dlib will be successfully installed.

1
  • this is the only one which worked for me, when running step 3 from an Administrator rights Anaconda powershell terminal
    – DaReal
    Dec 12, 2021 at 21:50
5

You need to install Cmake.

dlib is an c++ libary with python bindings. It needs to be builded first. My guess is this will happen automatically once you have installed Cmake

6
  • 1
    I have installed Cmake, could you please tell me how to make it work and with cmake what should i put in "Where is the source code?" and "Where to build the binaries?"
    – Drill
    Jan 30, 2017 at 18:25
  • @Drill just reinvoke pip install dlib.
    – TruckerCat
    Jan 30, 2017 at 19:06
  • @Drill make sure cmake is in your path variable
    – TruckerCat
    Jan 30, 2017 at 19:06
  • I tried the same and tried to invoke pip install dlib. it is throwing error "error MSB4 019: The imported project "C:\Microsoft.Cpp.Default.props" was not found. Confirm that the path in the <Import> declaration is correct, and that the file exists on disk." There is no "C:\Microsoft.Cpp.Default.props" in my system. Is there any way to resolve this? Sep 15, 2018 at 4:42
  • @AbhinavVaidya8 I am sorry, but I have no idea how to resolve this.
    – TruckerCat
    Sep 16, 2018 at 9:54
4

So basically I have been searching the solution for two days. I tried everything

  • Installing Cmake
  • Adding path
  • installing dlib from the links mentioned in the answers
  • Installing ## Heading ## numpy, scipy, matplotlib, pandas
  • etc etc etc

BUT THE ONLY SOLUTION THAT WORKED WAS INSTALLING MICROSOFT VISUAL STUDIO C++

After installing MS VS C++ I ran command pip install dlib and it is working like a charm. BEST OF LUCK

Link to download Visual Studio C++

https://visualstudio.microsoft.com/thank-you-for-downloading-visual-studio-for-cplusplus/?sku=Community&rel=16&rid=30005

1
  • Thank you Bilal! It's unbelievable how every single answer around seems to forget that CMake is NOT a compiler, and that people might not have any C++ compiler installed at all, particularly Python devs. I'm installing from scratch on a NUC and I'm just struggling on what exactly are the absolute minimum requirements to compile DLib. I'm installing like 16GB of VS C++ crap only to generate a 8MB pyc. Why is DLib not distributed compiled, like everything else, anyway?
    – Ricardo
    Dec 11, 2021 at 17:59
1

You have to install cmake as the error tells you.

you can follow this instructions https://www.learnopencv.com/install-dlib-on-windows/

or directly install cmake from here https://cmake.org/download/

Once cmake is installed pip install dlib should work.

I had vstudio building tools installed whe I did my test.

1

Choose dlib .whl file according to your installed python version. For example if installed python version is 3.6.7 , 64bit system or if python is 3.5.0 32 bit then choose dlib-19.5.1-cp36-cp36m-win_amd64.whl and dlib-18.17.100-cp35-none-win32.whl respectively.

Bolded text says the python supporting version.

Download wheel file from here or copy the link address

pip install dlib-19.5.1-cp36-cp36m-win_amd64.whl

for above method .whl file shoud be in the working directory

or

Below link for python3.6 supporting dlib link, for python 3.5 u can replace with dlib 35.whl link

pip install https://files.pythonhosted.org/packages/24/ea/81e4fc5b978277899b1c1a63ff358f1f645f9369e59d9b5d9cc1d57c007c/dlib-19.5.1-cp36-cp36m-win_amd64.whl#sha256=7739535b76eb40cbcf49ba98d894894d06ee0b6e8f18a25fef2ab302fd5401c7
1

1.use python 3.6.9 version

2.first install cmake.

conda install -c anaconda cmake
  1. use these command to install dlib

pip install https://pypi.python.org/packages/da/06/bd3e241c4eb0a662914b3b4875fc52dd176a9db0d4a2c915ac2ad8800e9e/dlib-19.7.0-cp36-cp36m-win_amd64.whl#md5=b7330a5b2d46420343fbed5df69e6a3f

1
  • This is the most simple way of doing it, on Windows. All u need to do is revert back to Python 3.6.x and do pip install cmake and then pip install https://pypi.python.org/packages/da/06/bd3e241c4eb0a662914b3b4875fc52dd176a9db0d4a2c915ac2ad8800e9e/dlib-19.7.0-cp36-cp36m-win_amd64.whl#md5=b7330a5b2d46420343fbed5df69e6a3f. I have used just this in my face detection system, for easy install. Check out at github.com/UBISOFT-1/Project_Exodus.git May 25, 2021 at 4:33
0

Just a quick update on what has worked for me (two years later). Davis King has provided two ways to add the latest python dlib (19.17.0) to any python environment in Windows 10 for me. Note, I run several Linux configs in Oracle VirtualBox but Windows 10 is my native OS which has access to the Nvidia GPU so i need an install on Windows 10. (Cannot access the GPU - easily - through VirtualBox).

First - the easiest:

pip install dlib

and the website link: https://pypi.org/project/dlib/

And then it can be easily be build from sources. Download from https://pypi.org/simple/dlib/ and follow instructions on http://dlib.net/compile.html.

Also, just found another way to access with Visual Studio 2019 (or 2017). Use vcpkg - see link https://vcpkg.readthedocs.io/en/latest/

I built dlib 19.17 on Windows 10 with CMake and it worked fine but then I found vcpkg and now the dlib libraries are integral to the Visual Studio. I no longer need to add all the external links to C++ and the linker.The version in vcpkg is currently 19.16-1 and it is built with full CUDA support.

Hope this helps others..

0

You can use vcpkg to install dlib.

If you don't have vcpkg, you can get it here (Read Quick Start)

After you got vcpkg, run:

vcpkg install dlib:x64-windows
0

I have recently installed dlib on python 3.7. First I have installed cmake from anaconda navigator (cmake version 3.14.0) Next i installed visual studio 2019 and installed Desktop development with C++ . Then I do pip install dlib and now its working

0

None of the answers worked for me. This is what worked Assuming you have anaconda python 3.7 installed

1) Dowload and install cmake(make sure to check the option to add cmake to system path during installation to avoid manually doing later) Download from this link cmake download

2) conda install -c conda-forge dlib

0

It is basically a two-step process:

  1. install cmap
pip install cmap
  1. install dlib
pip install https://pypi.python.org/packages/da/06/bd3e241c4eb0a662914b3b4875fc52dd176a9db0d4a2c915ac2ad8800e9e/dlib-19.7.0-cp36-cp36m-win_amd64.whl#md5=b7330a5b2d46420343fbed5df69e6a3f
0

If you're trying to install dlib on Windows 10 with Visual Studio 2019, then first perform:

pip install cmake

And set it in the environment variable. After that, make sure that you have the latest version of Visual Studio SDK installed. After that, perform:

pip install dlib

I hope this solves the problem

0

Update/Install Visual C++

Maybe try installing/updating Visual C++. Because this is necessary for CMake to run. You can install it from here, https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=15#

Installation with Wheel File

Run this:

pip install https://pypi.python.org/packages/da/06/bd3e241c4eb0a662914b3b4875fc52dd176a9db0d4a2c915ac2ad8800e9e/dlib-19.7.0-cp36-cp36m-win_amd64.whl#md5=b7330a5b2d46420343fbed5df69e6a3f

Installation from Internet

  1. Install CMake from https://cmake.org/download/
  2. Run this, set PATH="%PATH%;C:\Program Files\CMake\bin to add CMake to your path. You can also do this manually by Editing The Environment Variables. 3)Download the following, https://pypi.org/project/dlib/#files.
  3. In the specified folder in which you extracted the install files run the following, python setup.py install.
-1

Simple and 100% working trick

(Make sure you install cmake)

My Anaconda python ver : 3.6.8 (64 bit) | OS :Windows 10

python -m pip install https://files.pythonhosted.org/packages/0e/ce/f8a3cff33ac03a8219768f0694c5d703c8e037e6aba2e865f9bae22ed63c/dlib-19.8.1-cp36-cp36m-win_amd64.whl#sha256=794994fa2c54e7776659fddb148363a5556468a6d5d46be8dad311722d54bfcf

enter image description here

1
  • 1
    This is the same exact answer as @Marco D.G. ! whats new here?
    – Hossein
    Jul 5, 2020 at 11:12
-3

Install dlib in Windows

download dlib from https://github.com/davisking/dlib.git

download camke from https://cmake.org/download/

Extract cmake and configure it as Environment variable to the extracted path my it was C:\Users\admin\Downloads\cmake-3.8.1-win32-x86\cmake-3.8.1-win32-x86\bin

Now extract dlib zip file and go to dlib folder

Follow this commands

cd dlib/test
mkdir build
cd build
cmake ..
cmake --build . --config Release

Now go to Release folder which would be at dlib\test\build\Release and execute this command dtest.exe --runall

This process takes time as cmake compiles all C++ files so stay clam. Enjoy!!!

1
  • 1
    That doesn't install dlib. It just runs the unit tests.
    – Davis King
    May 26, 2017 at 10:49

Not the answer you're looking for? Browse other questions tagged or ask your own question.