使用Visual Studio 2015库安装dlib时遇报错求助
Hey there, let's work through this dlib installation issue you're hitting. The key error here is package init file 'dlib\__init__.py' not found—this usually points to either an incomplete source package or a misconfigured build environment. Here's how to fix it step by step:
1. Ensure You Have the Complete dlib Source Code
The missing __init__.py suggests your downloaded dlib package might be incomplete. Instead of grabbing a partial zip, grab the full source from the official repo:
- Open your terminal/command prompt and run:
git clone https://github.com/davisking/dlib.git - Once cloned, navigate into the dlib root directory (this is where the
setup.pyfile lives—don't go into the nesteddlibsubfolder yet).
2. Verify Visual Studio 2015 Configuration
Dlib requires a working C++ build chain, so double-check these:
- Make sure you installed the C++ Development Tools when setting up VS2015. This includes the compiler, Windows SDK, and related components. If you skipped this, re-run the VS installer and add those components.
- Use the correct VS command prompt: Launch the "VS2015 x64 Native Tools Command Prompt" (or x86 if your Python is 32-bit). This ensures all compiler environment variables are properly set—running the install from a regular command prompt won't have these.
3. Run the Install Correctly
From the VS command prompt:
- If you're using a virtual environment, activate it first.
- Navigate to the dlib root directory (where
setup.pyis located). - Run one of these commands (pip is more reliable for dependency handling):
Or if you prefer setup.py directly:pip install .python setup.py install
4. Alternative: Use a Pre-built Wheel (Skip Compilation)
If compiling still gives you trouble, you can use a pre-built dlib wheel package that matches your Python version and Windows architecture. Once you've downloaded the correct .whl file, install it with:
pip install dlib-<version>-<python-tag>-<arch>.whl
This should resolve the missing __init__.py error and get dlib installed properly.
内容的提问来源于stack exchange,提问作者Mouhsine Elachbi

