2017-07-10 Building dlib for Python 3.6 and boost_python on WindowsΒΆ

dlib is quite difficult to build on Windows for Python 3.6. A compiled version exists on PyPi/dlib for Python 3.5 but the version for Python 3.6 remains unavailable unless you are using Anaconda: Installing Dlib on Anaconda Python on Windows. The blog Install Dlib on Windows even recommends not to try and to use conda (with Anaconda) instead:

conda install -c conda-forge dlib=19.4

It seems easier to do it on Ubuntu Install dlib on Ubuntu. As I was still trying to go on with the compilation, I discovered this tool vcpkg which helps installing C++ packages on Windows. I followed the instructions to build it:

git clone https://github.com/Microsoft/vcpkg
powershell -exec bypass scripts\bootstrap.ps1

And I compiled boost:

vcpkg install boost:x64-windows

Be patient because installing boost takes a while because it builds everything. One issue though: it does not include Python: issue 78. The same instruction works for dlib:

vcpkg install dlib:x64-windows

But it is yet impossible to build the python extension dlib for Windows. I had to start from scratch. So I started to build boost_python on my own. The tutorial is easy to follow but it took a week to find the good page telling how to get the 64 bits version of it. The trick I was missing is to build boost_python from a VS2015 x64 Native Tools Command Prompt otherwise the builds gets stuck in 32 bits.

This part is summarize in the script build_boost_python_static.bat. Then comes dlib. I also followed the tutorial which explains how to build the C++ version of it. No issue there. The first part starts with:

python -u setup.py build_ext --inplace --yes USE_AVX_INSTRUCTIONS
python -u setup.py bdist_wheel

If fails to find the Python static libraries because the linker cannot find them and boost_python because the name is different. So I copied tham at the same location as boost_python build.

set version=1_64_0
set BOOST_LIBRARYDIR=something like ...\boost_%version%\boost_%version%\stage\x64\lib
copy %pythonexe%\libs\*.lib %BOOST_LIBRARYDIR%
copy %BOOST_LIBRARYDIR%\libboost_python3-vc140-mt-s-1_64.lib %BOOST_LIBRARYDIR%\libboost_python-vc140-mt-s-1_64.lib
copy %BOOST_LIBRARYDIR%\libboost_numpy3-vc140-mt-s-1_64.lib %BOOST_LIBRARYDIR%\libboost_numpy3-vc140-mt-s-1_64.lib

The full process is given by build_dlib.bat. It was quite a long journey. You can find my build at dlib-19.4.99-cp36-cp36m-win_amd64.whl.

More about vcpkg: