How to install dlib for Python with Visual Studio 2017 on Windows 10 (2018)

Royce Chua
4 min readDec 9, 2018

--

This tutorial will cover the installation of dlib on Python with the Visual Studio 2017. For those of you that don’t know what Dlib is, I’ve provided the definition of its creators from their page dlib.net.

Dlib is a modern C++ toolkit containing machine learning algorithms and tools for creating complex software in C++ to solve real world problems.

Most often dlib is partnered with OpenCV. So this tutorial will be helpful for people who want to install dlib for their Computer Vision projects and use Python.

To get started, first you need to have Python installed in your computer. Since we are using the Visual Studio 2017 we have an option there to have Python included in the installation which integrates it immediately with Visual Studio. So you may or may not install Python independently.

If you want an independent installation and just want to use some features of Visual Studio 2017 you can follow this section below if not feel free to skip it and just include Python in the Visual Studio 2017 installation.

I would strongly suggest using Python version 3.6.x for now.

Download link: https://www.python.org/downloads/release/python-367/
**Note: For convenience, always select or check ADD TO PATH, and customize your installation path to C:\ or C:\Program Files for convenience.

Second, you need to install CMake which is

an extensible, open-source system that manages the build process in an operating system and in a compiler-independent manner.

Download link: https://cmake.org/download/

CMake will be the one to create the build files from the C++ dlib library using the native Visual Studio build tools.

The approach that will be used here is using an installation of Visual Studio 2017 Community edition, which is the setup I have on this computer.

Download link: https://visualstudio.microsoft.com/downloads/
**Note: Make sure to select the Community edition.

After downloading, open the Visual Studio Installer and just run through the process until you are taken to this screen.

This is where you choose which features of Visual Studio 2017 you would like to download and install. Selections may vary for your specific use of the Studio but make sure to have the Visual C++ build tools selected and you would want to have the 4 items on the right to be checked which are: Windows 10 SDK, Visual C++ build tools for CMake, Testing tools core features — Build tools, and VC ++ 2015.3 v 14.00 toolset for desktop.

Then proceed with the installation. It will be a long installation as the file size of the download is in GB. After installation press the Windows key and type Edit the System Environment variables. A window will pop-up, select environment variables at the bottom right.

In the new window, select New, then add VCTargetsPath as the variable name and
C:\Program Files (x86)\Microsoft Visual Studio\2017\BuildTools\Common7\IDE\VC\VCTargets as the variable value.

Make sure to follow this step.

You can make it a system variable if there are more users you would like to share dlib with. After select ok and close the windows.

Assuming you have added Python successfully to your PATH environment variable. Open your terminal (cmd) and type

pip install dlib

As of 2018, the library should automatically be fetched downloaded and installed for you without having to do a lot of extra work other than setup of CMake and Visual Studio Build tools.

My dlib was already downloaded and cached I just needed to install, but for yours it may indicate a download progress bar on the cmd.

If you’ve found this tutorial helpful please like my blog and share it. If you have any questions let me know in the comments below.

Problems you might encounter (or have encountered before reading through this tutorial)

One problem that you might encounter is

MSB4019: 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.

This was really my problem for a couple of days and what it really means is that it’s looking for your build tools and its unable to locate it. Creating the environment variable will solve this problem.

Another error you might encounter

C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V110\Microsoft.Cpp.Platform.targets (44): The builds tools for v140 (Platform Toolset = ‘v140’) cannot be found. To build using the v140 build tools, either click the Project menu or right-click the solution, and then select “Update VC++ Projects…”. Install v140 to build using the v140 build tools.

This is solved by installing the following below especially
VC++ 2015.3 v14.00 (v140) toolset for desktop
**Note: I cannot stress over this enough, as I’ve been figuring these errors out for the past couple of days on Microsoft forums and on Stackoverflow.

Following the steps above in the tutorial, would most certainly help you in installing Dlib using Visual Studio 2017.

Originally published at rctechblogs.wordpress.com on December 9, 2018.

--

--