安装dlib出现以下问题
(suanfa) PS D:\file\code> pip install dlib
Collecting dlib
Downloading dlib-19.24.2.tar.gz (11.8 MB)
━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━━ 11.8/11.8 MB 3.5 MB/s eta 0:00:00
Installing build dependencies ... done
Getting requirements to build wheel ... done
Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: dlib
Building wheel for dlib (pyproject.toml) ... error
error: subprocess-exited-with-error
× Building wheel for dlib (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [73 lines of output]
running bdist_wheel
running build
running build_ext
<string>:125: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
Building extension for Python 3.9.18 (main, Sep 11 2023, 14:09:26) [MSC v.1916 64 bit (AMD64)]
Invoking CMake setup: 'cmake C:\Users\13301\AppData\Local\Temp\pip-install-0krv98w2\dlib_d734e3d0865e402592f3db3e3fb65f7c\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\13301\AppData\Local\Temp\pip-install-0krv98w2\dl
ib_d734e3d0865e402592f3db3e3fb65f7c\build\lib.win-amd64-cpython-39 -DPYTHON_EXECUTABLE=E:\Anaconda\envs\suanfa\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\13301\AppData\Local\Temp\pip-install-0krv98w2\dlib_d734e3d0865e402592f3db3e3fb65f7c\build\lib.win-amd64-cpython-39 -A x64'
-- Building for: NMake Makefiles
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 "E:\Anaconda\envs\suanfa\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
main()
File "E:\Anaconda\envs\suanfa\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
json_out['return_val'] = hook(**hook_input['kwargs'])
File "E:\Anaconda\envs\suanfa\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 251, in build_wheel
return _build_backend().build_wheel(wheel_directory, config_settings,
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\build_meta.py", line 410, in build_wheel
return self._build_with_temp_dir(
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\build_meta.py", line 395, in _build_with_temp_dir
self.run_setup()
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup
exec(code, locals())
File "<string>", line 218, in <module>
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\__init__.py", line 104, in setup
return distutils.core.setup(**attrs)
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
return run_commands(dist)
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
dist.run_commands()
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands
self.run_command(cmd)
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\dist.py", line 967, in run_command
super().run_command(command)
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
cmd_obj.run()
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\wheel\bdist_wheel.py", line 368, in run
self.run_command("build")
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
self.distribution.run_command(command)
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\dist.py", line 967, in run_command
super().run_command(command)
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
cmd_obj.run()
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\_distutils\command\build.py", line 131, in run
self.run_command(cmd_name)
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
self.distribution.run_command(command)
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\dist.py", line 967, in run_command
super().run_command(command)
File "C:\Users\13301\AppData\Local\Temp\pip-build-env-ptouojkc\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
cmd_obj.run()
File "<string>", line 130, in run
File "<string>", line 167, in build_extension
File "E:\Anaconda\envs\suanfa\lib\subprocess.py", line 373, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\13301\\AppData\\Local\\Temp\\pip-install-0krv98w2\\dlib_d734e3d0865e402592f3db3e3fb65f7c\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\13301\\AppDa
ta\\Local\\Temp\\pip-install-0krv98w2\\dlib_d734e3d0865e402592f3db3e3fb65f7c\\build\\lib.win-amd64-cpython-39', '-DPYTHON_EXECUTABLE=E:\\Anaconda\\envs\\suanfa\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\13301\\AppData\\Local\\Temp\\pip-install-0krv98w2\\dlib_d734e3d0865e402592f3db3e3fb65f7c\\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
Failed to build dlib
ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects
经了解,可能是由于缺少依赖项或配置不正确导致的。具体的错误消息指出在Windows上构建Python扩展需要安装Visual Studio C++。
方法一:(麻烦,不想用)
-
安装Visual Studio:确保你的系统上已经安装了Visual Studio。你可以从微软官方网站下载安装。选择与你系统配置相符的版本。
-
验证Visual C++安装:在安装完Visual Studio后,确保已经安装了Visual C++组件。打开Visual Studio Installer,选择你已安装的Visual Studio版本,检查是否安装了"Desktop development with C++"工作负载。如果没有安装,请执行安装。
-
更新CMake:更新你的CMake版本到最新版。你可以从CMake官方网站下载安装。
-
设置环境:如果你使用Anaconda,确保在运行
pip install dlib
命令之前先激活你的suanfa
环境。你可以通过运行以下命令来完成:conda activate suanfa
-
重试安装:完成上述步骤后,再次运行
pip install dlib
命令来重新安装dlib
。
方法二:
conda install -c https://conda.anaconda.org/conda-forge dlib
我的电脑有anaconda,所以进入对应环境,用命令行直接下载
方法三:
配置文件下载,whl直接下载也挺方便的,刚学Python下载dlib用过,记录一下
Links for dlib (pypi.org)从这个网站下载
如果单击下载不上,使用下图右键打开
之后就直接下载了
之后进入命令行进入对应环境下载
pip intall F:\13301\下载\dlib-19.8.1-cp36-cp36m-win_amd64.whl
将F:\13301\下载\dlib-19.8.1-cp36-cp36m-win_amd64.whl修改为自己的路径即可