(base) C:\Users\XC>pip install dlib==19.7.0 Collecting dlib==19.7.0 Using cached dlib-19.7.0.tar.gz (4.0 MB) Preparing metadata (setup.py) ... done Building wheels for collected packages: dlib DEPRECATION: Building 'dlib' using the legacy setup.py bdist_wheel mechanism, which will be removed in a future version. pip 25.3 will enforce this behaviour change. A possible replacement is to use the standardized build interface by setting the `--use-pep517` option, (possibly combined with `--no-build-isolation`), or adding a `pyproject.toml` file to the source tree of 'dlib'. Discussion can be found at https://github.com/pypa/pip/issues/6334 Building wheel for dlib (setup.py) ... error error: subprocess-exited-with-error × python setup.py bdist_wheel did not run successfully. │ exit code: 1 ╰─> [76 lines of output] C:\Users\XC\AppData\Local\Temp\pip-install-t9ptlaxa\dlib_04710a2f6a364c8391ea5e7017c308fb\setup.py:360: SyntaxWarning: invalid escape sequence '\(' major = re.findall("set\(CPACK_PACKAGE_VERSION_MAJOR.*\"(.*)\"", open('dlib/CMakeLists.txt').read())[0] C:\Users\XC\AppData\Local\Temp\pip-install-t9ptlaxa\dlib_04710a2f6a364c8391ea5e7017c308fb\setup.py:361: SyntaxWarning: invalid escape sequence '\(' minor = re.findall("set\(CPACK_PACKAGE_VERSION_MINOR.*\"(.*)\"", open('dlib/CMakeLists.txt').read())[0] C:\Users\XC\AppData\Local\Temp\pip-install-t9ptlaxa\dlib_04710a2f6a364c8391ea5e7017c308fb\setup.py:362: SyntaxWarning: invalid escape sequence '\(' patch = re.findall("set\(CPACK_PACKAGE_VERSION_PATCH.*\"(.*)\"", open('dlib/CMakeLists.txt').read())[0] C:\Users\XC\AppData\Local\Temp\pip-install-t9ptlaxa\dlib_04710a2f6a364c8391ea5e7017c308fb\setup.py:72: DeprecationWarning: Use shutil.which instead of find_executable _cmake_path = find_executable("cmake") running bdist_wheel running build Detected Python architecture: 64bit Detected platform: win32 Configuring cmake ... D:\Anaconda\Lib\subprocess.py:1029: RuntimeWarning: line buffering (buffering=1) isn't supported in binary mode, the default buffer size will be used self.stdout = io.open(c2pread, 'rb', bufsize) Traceback (most recent call last): File "<string>", line 2, in <module> exec(compile(''' ~~~~^^^^^^^^^^^^ # This is <pip-setuptools-caller> -- a caller that pip uses to run setup.py ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ...<32 lines>... exec(compile(setup_py_code, filename, "exec")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ ''' % ('C:\\Users\\XC\\AppData\\Local\\Temp\\pip-install-t9ptlaxa\\dlib_04710a2f6a364c8391ea5e7017c308fb\\setup.py',), "<pip-setuptools-caller>", "exec")) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "<pip-setuptools-caller>", line 35, in <module> File "C:\Users\XC\AppData\Local\Temp\pip-install-t9ptlaxa\dlib_04710a2f6a364c8391ea5e7017c308fb\setup.py", line 616, in <module> setup( ~~~~~^ name='dlib', ^^^^^^^^^^^^ ...<40 lines>... ], ^^ ) ^ File "D:\Anaconda\Lib\site-packages\setuptools\__init__.py", line 108, in setup return distutils.core.setup(**attrs) ~~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "D:\Anaconda\Lib\site-packages\setuptools\_distutils\core.py", line 184, in setup return run_commands(dist) File "D:\Anaconda\Lib\site-packages\setuptools\_distutils\core.py", line 200, in run_commands dist.run_commands() ~~~~~~~~~~~~~~~~~^^ File "D:\Anaconda\Lib\site-packages\setuptools\_distutils\dist.py", line 970, in run_commands self.run_command(cmd) ~~~~~~~~~~~~~~~~^^^^^ File "D:\Anaconda\Lib\site-packages\setuptools\dist.py", line 945, in run_command super().run_command(command) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "D:\Anaconda\Lib\site-packages\setuptools\_distutils\dist.py", line 989, in run_command cmd_obj.run() ~~~~~~~~~~~^^ File "D:\Anaconda\Lib\site-packages\setuptools\command\bdist_wheel.py", line 373, in run self.run_command("build") ~~~~~~~~~~~~~~~~^^^^^^^^^ File "D:\Anaconda\Lib\site-packages\setuptools\_distutils\cmd.py", line 316, in run_command self.distribution.run_command(command) ~~~~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "D:\Anaconda\Lib\site-packages\setuptools\dist.py", line 945, in run_command super().run_command(command) ~~~~~~~~~~~~~~~~~~~^^^^^^^^^ File "D:\Anaconda\Lib\site-packages\setuptools\_distutils\dist.py", line 989, in run_command cmd_obj.run() ~~~~~~~~~~~^^ File "C:\Users\XC\AppData\Local\Temp\pip-install-t9ptlaxa\dlib_04710a2f6a364c8391ea5e7017c308fb\setup.py", line 410, in run self.build_dlib() ~~~~~~~~~~~~~~~^^ File "C:\Users\XC\AppData\Local\Temp\pip-install-t9ptlaxa\dlib_04710a2f6a364c8391ea5e7017c308fb\setup.py", line 567, in build_dlib if run_process(cmake_cmd): ~~~~~~~~~~~^^^^^^^^^^^ File "C:\Users\XC\AppData\Local\Temp\pip-install-t9ptlaxa\dlib_04710a2f6a364c8391ea5e7017c308fb\setup.py", line 303, in run_process while t.isAlive(): ^^^^^^^^^ AttributeError: 'Thread' object has no attribute 'isAlive'. Did you mean: 'is_alive'? [end of output] note: This error originates from a subprocess, and is likely not a problem with pip. ERROR: Failed building wheel for dlib Running setup.py clean for dlib Failed to build dlib ERROR: Failed to build installable wheels for some pyproject.toml based projects (dlib)
时间: 2025-07-04 18:15:44 浏览: 14
从错误日志来看,`pip install dlib==19.7.0` 失败的核心原因是 **Python 3.9+ 中 `Thread.isAlive()` 方法已被弃用**(需替换为 `Thread.is_alive()`),而 `dlib-19.7.0` 的源码未适配这一变更。以下是详细解决方案:
---
### **解决方案**
#### 方法 1:修改源码后手动安装
1. **下载源码包**:
```bash
pip download dlib==19.7.0 --no-deps
```
解压生成的 `dlib-19.7.0.tar.gz` 文件。
2. **修改 `setup.py`**:
- 找到文件中的 `t.isAlive()`(约第 303 行),替换为 `t.is_alive()`。
- 同时修复 `SyntaxWarning`(可选):
```python
# 将以下代码中的反斜杠转义替换为原始字符串或双反斜杠
major = re.findall(r"set\(CPACK_PACKAGE_VERSION_MAJOR.*\"(.*)\"", open('dlib/CMakeLists.txt').read())[0]
```
3. **本地安装**:
```bash
pip install /path/to/modified/dlib-19.7.0
```
#### 方法 2:使用更高版本的 `dlib`
直接安装兼容 Python 3.9+ 的版本(如 `19.24.0`):
```bash
pip install dlib --upgrade
```
#### 方法 3:通过 Conda 安装(推荐)
Conda 的预编译包通常已解决兼容性问题:
```bash
conda install -c conda-forge dlib=19.7.0
```
#### 方法 4:降级 Python 版本
临时使用 Python 3.8(`dlib-19.7.0` 官方支持的最高版本):
```bash
conda create -n py38 python=3.8
conda activate py38
pip install dlib==19.7.0
```
---
### **关键错误分析**
1. **`Thread.isAlive()` 问题**:
- Python 3.9+ 移除了 `threading.Thread.isAlive()`,需改用 `is_alive()`。
- 这是 `dlib-19.7.0` 的遗留代码缺陷。
2. **CMake 配置警告**:
- 日志中 `Configuring cmake ...` 后的错误表明 CMake 未正确安装或未加入系统路径。
3. **`SyntaxWarning`**:
- 源码中的正则表达式使用了无效的转义序列(如 `\(`),虽不影响运行但需修复。
---
### **附加建议**
- **安装 CMake**:确保系统已安装 CMake 并添加到环境变量:
```bash
conda install -c conda-forge cmake
```
- **启用 Pip 的 PEP 517 构建**(可能绕过部分问题):
```bash
pip install dlib==19.7.0 --use-pep517
```
---
阅读全文
相关推荐



















