Windows10下Python3.7安装dlib(人脸识别)报错的解决方法咨询
Hey there, let's break down why you're hitting this error and fix it step by step. The core issues here are:
- CMake is trying to use the
NMake Makefilesgenerator, which doesn't support specifying thex64platform - Your environment is missing a proper C/C++ compiler required to build dlib from source
Here are two reliable solutions to get dlib installed:
Option 1: Use a Pre-built Wheel (Easiest & Fastest)
Building from source is error-prone on Windows. Instead, use a pre-compiled wheel package tailored for your Python 3.7 64-bit environment:
- Find the correct dlib wheel file matching Python 3.7 and Windows 64-bit (look for a file named something like
dlib-19.18.0-cp37-cp37m-win_amd64.whl) - Download it to your local machine
- Open a command prompt, navigate to the folder where you saved the wheel, and run:
pip install dlib-19.18.0-cp37-cp37m-win_amd64.whl
This skips the entire source compilation process and gets you up and running in minutes.
Option 2: Fix Source Compilation (If You Need to Build From Source)
If you must build dlib from source, follow these steps to configure your environment correctly:
Install Visual Studio Build Tools
- Download and install Visual Studio Build Tools (2017 or newer)
- During installation, select the Desktop development with C++ workload
- Ensure the following components are checked:
- MSVC v141 (or newer) C++ x64/x86 build tools
- Windows 10 SDK
- CMake tools for Windows
Use the Correct Command Prompt
- Don't use a regular command prompt or Anaconda prompt. Instead, open the x64 Native Tools Command Prompt for VS 20XX (matches your installed VS version)
- This prompt automatically configures all environment variables for the 64-bit C/C++ compiler and CMake
Re-run the Installation
- Navigate to your extracted dlib folder in the VS command prompt
- Run either of these commands:
orpython setup.py installpip install .
Why This Works
The VS Native Tools Command Prompt sets up the correct compiler paths and tells CMake to use the MSBuild generator (instead of NMake), which fully supports the x64 platform specification. This fixes both the generator and compiler missing errors you saw earlier.
内容的提问来源于stack exchange,提问作者Sri

