我在安装dlib的时候报错,具体如下
(py39) C:\Users\Administrator>pip install dlib19.22.0 Looking in indexes: https://repo.huaweicloud.com/repository/pypi/simple/ Collecting dlib19.22.0 Using cached https://repo.huaweicloud.com/repository/pypi/packages/11/93/ec41d6ef7e769977aa08e49441c52276da27859f12dcbf1c6deb96ce5e9f/dlib-19.22.0.tar.gz (7.4 MB) Preparing metadata (setup.py) … done Building wheels for collected packages: dlib 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] running bdist_wheel running build running build_py running build_ext C:\Users\Administrator\AppData\Local\Temp\pip-install-pcyde4_8\dlib_4d9ceab6d1244d8da8c377a7737a2a29\setup.py:129: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead. if LooseVersion(cmake_version) < ‘3.1.0’: Building extension for Python 3.9.19 (main, Mar 21 2024, 17:21:27) [MSC v.1916 64 bit (AMD64)] Invoking CMake setup: ‘cmake C:\Users\Administrator\AppData\Local\Temp\pip-install-pcyde4_8\dlib_4d9ceab6d1244d8da8c377a7737a2a29\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Administrator\AppData\Local\Temp\pip-install-pcyde4_8\dlib_4d9ceab6d1244d8da8c377a7737a2a29\build\lib.win-amd64-cpython-39 -DPYTHON_EXECUTABLE=D:\Users\Administrator\anaconda3\envs\py39\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\Administrator\AppData\Local\Temp\pip-install-pcyde4_8\dlib_4d9ceab6d1244d8da8c377a7737a2a29\build\lib.win-amd64-cpython-39 -A x64’ – Building for: NMake Makefiles CMake Deprecation Warning at CMakeLists.txt:2 (CMAKE_MINIMUM_REQUIRED): Compatibility with CMake < 3.5 will be removed from a future version of CMake.
Update the VERSION argument <min> value or use a ...<max> suffix to tell CMake that the project does not need compatibility with older versions.
CMake Error at CMakeLists.txt:5 (message):
!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!! You must use Visual Studio to build a python extension on windows. If you are getting this error it means you have not installed Visual C++. Note that there are many flavors of Visual Studio, like Visual Studio for C# development. You need to install Visual Studio for C++. !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
– Configuring incomplete, errors occurred! Traceback (most recent call last): File ““, line 2, in File ““, line 34, in File “C:\Users\Administrator\AppData\Local\Temp\pip-install-pcyde4_8\dlib_4d9ceab6d1244d8da8c377a7737a2a29\setup.py”, line 222, in setup( File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools__init__.py”, line 103, in setup return distutils.core.setup(**attrs) File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools_distutils\core.py”, line 185, in setup return run_commands(dist) File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools_distutils\core.py”, line 201, in run_commands dist.run_commands() File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools_distutils\dist.py”, line 969, in run_commands self.run_command(cmd) File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools\dist.py”, line 989, in run_command super().run_command(command) File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools_distutils\dist.py”, line 988, in run_command cmd_obj.run() File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\wheel\bdist_wheel.py”, line 364, in run self.run_command(“build”) File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools_distutils\cmd.py”, line 318, in run_command self.distribution.run_command(command) File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools\dist.py”, line 989, in run_command super().run_command(command) File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools_distutils\dist.py”, line 988, in run_command cmd_obj.run() File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools_distutils\command\build.py”, line 131, in run self.run_command(cmd_name) File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools_distutils\cmd.py”, line 318, in run_command self.distribution.run_command(command) File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools\dist.py”, line 989, in run_command super().run_command(command) File “D:\Users\Administrator\anaconda3\envs\py39\lib\site-packages\setuptools_distutils\dist.py”, line 988, in run_command cmd_obj.run() File “C:\Users\Administrator\AppData\Local\Temp\pip-install-pcyde4_8\dlib_4d9ceab6d1244d8da8c377a7737a2a29\setup.py”, line 134, in run self.build_extension(ext) File “C:\Users\Administrator\AppData\Local\Temp\pip-install-pcyde4_8\dlib_4d9ceab6d1244d8da8c377a7737a2a29\setup.py”, line 171, in build_extension subprocess.check_call(cmake_setup, cwd=build_folder) File “D:\Users\Administrator\anaconda3\envs\py39\lib\subprocess.py”, line 373, in check_call raise CalledProcessError(retcode, cmd) subprocess.CalledProcessError: Command ‘[‘cmake’, ‘C:\Users\Administrator\AppData\Local\Temp\pip-install-pcyde4_8\dlib_4d9ceab6d1244d8da8c377a7737a2a29\tools\python’, ‘-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Administrator\AppData\Local\Temp\pip-install-pcyde4_8\dlib_4d9ceab6d1244d8da8c377a7737a2a29\build\lib.win-amd64-cpython-39’, ‘-DPYTHON_EXECUTABLE=D:\Users\Administrator\anaconda3\envs\py39\python.exe’, ‘-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\Administrator\AppData\Local\Temp\pip-install-pcyde4_8\dlib_4d9ceab6d1244d8da8c377a7737a2a29\build\lib.win-amd64-cpython-39’, ‘-A’, ‘x64’]’ returned non-zero exit status 1. [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: Could not build wheels for dlib, which is required to install pyproject.toml-based projects
这个错误信息表明在安装 dlib 时出现了问题。具体来说,出现了以下几个关键问题:
**缺少 Visual C**:dlib 在 Windows 上需要使用 Visual C 编译器来构建,但是您的系统中似乎没有安装 Visual C。这是由于 CMake 脚本检测到缺少 Visual C 而导致的构建失败。
依赖项问题:dlib 可能还有其他依赖项,如果这些依赖项没有正确安装或配置,也会导致构建失败。
针对这个问题,您可以尝试以下几个解决方案:
**安装 Visual C**:您需要安装 Visual C,包括对应的 C 编译器和构建工具。您可以从 Visual Studio 官方网站下载并安装 Visual Studio,选择包含 C 工作负载的版本。
检查依赖项:确保您的系统中已安装 dlib 所需的所有依赖项。可以查阅 dlib 的官方文档或 GitHub 页面,了解需要安装的依赖项。
使用预编译版本:如果您不想自己构建 dlib,可以尝试安装预编译的版本。您可以查看 dlib 的 GitHub 发行页面,看是否有适用于您系统的预编译版本。
更新 pip 和 setuptools:有时候更新 pip 和 setuptools 到最新版本可以解决一些安装问题。您可以尝试运行以下命令更新它们:
pip install --upgrade pip setuptools
尝试上述解决方案中的一个或多个,看看是否能够解决您遇到的问题。如果问题仍然存在,可能需要更多的调试和排查。