On the Internet, dlib is installed with Visual Studio. A visual studio 2019 installation package is more than 30G, and the relevant program can be compiled with mingw-w64.
Install MingW-W64
The msys2 used here: https://www.msys2.org/
Install msys2
Refer to the official website, for example, the installation location is c:\msys64\
Use domestic mirror source
c:\msys64\etc\pacman.d\
- mirrorlist.mingw32
- mirrorlist.mingw64
- mirrorlist.msys
Put Tsinghua source in the first line of these three files
# the CN mirror url
Server = https://mirrors.tuna.tsinghua.edu.cn/msys2/mingw/i686/
Install mingw-w64
msys2 minGW 64-bit
start menu
pacman -Syu
pacman -Su
pacman -S --needed base-devel mingw-w64-x86_64-toolchain
Add mingw64's gcc to windows environment variables
The address is C:\msys64\mingw64\bin
, add environment variables to search by yourself
CUDA runtime library
The mingw compiler on the windows platform does not support CUDA, so even if you have a graphics card and CUDA, it will not install the CUDA version of dlib. At present, only visual studio supports CUDA on the windows platform.
Compile dlib as c library
Download the code and create related directories
cd /d d:\
git clone https://github.com/davisking/dlib.git
cd dlib
mkdir build
mkdir dist
cd build
Create compilation file
-G "MinGW Makefiles" This is the key, which means to generate Makefile files available for MinGW
cmake -G "MinGW Makefiles" -DCMAKE_INSTALL_PREFIX=D:\dlib\dist -DCMAKE_C_COMPILER=gcc -DCMAKE_CXX_COMPILER=g++ -DCMAKE_BUILD_TYPE=Release -DCMAKE_MAKE=mingw32-make ..
No surprises, it will succeed
Compile 4 is the number of your cpu cores
mingw32-make -j4
installation
mingw32-make install
The final files will be in the d:\dlib\dist
directory
Compile the wheel file of python
The file obtained by the following method is invalid. Don't try
If you have performed the above compilation, you need to clean up the build folder by yourself
Switch to the 19.20 branch
The latest version of the python package must be compiled with VS
19.20 can be compiled, but the red umbrella will be triggered when compiling, you can switch to 19.19
git checkout v19.20
Modify the source code
setup.py line 149
MinGW does not have parameters such as'-A' and'X64', and mingw's multi-thread compilation should be'-j'. So modify it as follows, comment out'-A','X64', and change it to 4-thread compilation.
if platform.system() == "Windows":
cmake_args += ['-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_{}={}'.format(cfg.upper(), extdir)]
# if sys.maxsize > 2**32:
# cmake_args += ['-A', 'x64']
# # Do a parallel build
# build_args += ['--', '/m']
build_args += ['--', '-j4']
carried out
python setup.py -G "MinGW Makefiles" bdist_wheel
python package
dlib-19.19.0-cp37-cp37m-win_amd64.whl (3.7MB)
dist directory is the windows version of dlib
pip install dlib-19.19.0-cp37-cp37m-win_amd64.whl
Installation of face_recognition
can be directly successful
pip3 install face_recognition
**粗体** _斜体_ [链接](http://example.com) `代码` - 列表 > 引用
。你还可以使用@
来通知其他用户。