關于python中DLIB包無法安裝問題解決辦法
本文章是基于VScode的dlib包無法安裝的解決方案。
Cmake支持
問題描述(錯誤碼展示)
Collecting dlib
Using cached dlib-19.24.9.tar.gz (3.4 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'done'
Building wheels for collected packages: dlib
Building wheel for dlib (pyproject.toml): started
Building wheel for dlib (pyproject.toml): finished with status 'error'
Failed to build dlib
Note: you may need to restart the kernel to use updated packages.
error: subprocess-exited-with-error
× Building wheel for dlib (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [48 lines of output]
running bdist_wheel
running build
running build_ext
Traceback (most recent call last):
File "e:\python310\lib\runpy.py", line 196, in _run_module_as_main
return _run_code(code, main_globals, None,
File "e:\python310\lib\runpy.py", line 86, in _run_code
exec(code, run_globals)
File "E:\python310\Scripts\cmake.exe\__main__.py", line 4, in <module>
ModuleNotFoundError: No module named 'cmake'
================================================================================
================================================================================
================================================================================
CMake is not installed on your system!
Or it is possible some broken copy of cmake is installed on your system.
It is unfortunately very common for python package managers to include
broken copies of cmake. So if the error above this refers to some file
path to a cmake file inside a python or anaconda or miniconda path then you
should delete that broken copy of cmake from your computer.
Instead, please get an official copy of cmake from one of these known good
sources of an official cmake:
- cmake.org (this is how windows users should get cmake)
- apt install cmake (for Ubuntu or Debian based systems)
- yum install cmake (for Redhat or CenOS based systems)
On a linux machine you can run `which cmake` to see what cmake you are
actually using. If it tells you it's some cmake from any kind of python
packager delete it and install an official cmake.
More generally, cmake is not installed if when you open a terminal window
and type
cmake --version
you get an error. So you can use that as a very basic test to see if you
have cmake installed. That is, if cmake --version doesn't run from the
same terminal window from which you are reading this error message, then
you have not installed cmake. Windows users should take note that they
need to tell the cmake installer to add cmake to their PATH. Since you
can't run commands that are not in your PATH. This is how the PATH works
on Linux as well, but failing to add cmake to the PATH is a particularly
common problem on windows and rarely a problem on Linux.
================================================================================
================================================================================
================================================================================
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for dlib
ERROR: Failed to build installable wheels for some pyproject.toml based projects (dlib)上述一段描述,主要簡化為兩點:(1)dlib包無法安裝,在下載過程中暫停。(2)系統(tǒng)描述問題為缺少Cmake支持。
原因是由于dlib 是一個依賴 CMake 進行編譯的 C++ 庫,因此必須先正確安裝 CMake。
需要注意的是,Cmake不是python中的包。而是一款軟件,需要在Cmake下載官網(wǎng)下載。
裝載流程
在電腦上下載Windows x64 Installer:。在等待過程中可以通過WIN+R調出任務運行框,

通過命令CMD調出管理員窗口,通過輸入cmake --version查看是否安裝Cmake或者安裝的版本號。

如果在安裝前試圖在python的包中下載了相應名稱的包,請卸載相應的包,或者通過在終端中輸入pip uninstall Cmake一鍵卸載。
安裝步驟
打開安裝程序

選擇ACCEPT

選擇添加到系統(tǒng)路徑 ???????

可以選擇C盤以外的路徑 ??????? ???????

然后一直安裝,等待安裝完成。
關于在VScode中出現(xiàn)的其他問題
問題描述
Collecting dlib
Using cached dlib-19.24.9.tar.gz (3.4 MB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'done'
Building wheels for collected packages: dlib
Building wheel for dlib (pyproject.toml): started
Building wheel for dlib (pyproject.toml): finished with status 'error'
Failed to build dlib
Note: you may need to restart the kernel to use updated packages.
error: subprocess-exited-with-error
× Building wheel for dlib (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [75 lines of output]
running bdist_wheel
running build
running build_ext
<string>:163: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
Building extension for Python 3.10.9 (tags/v3.10.9:1dd9be6, Dec 6 2022, 20:01:21) [MSC v.1934 64 bit (AMD64)]
Invoking CMake setup: 'cmake C:\Users\Dell\AppData\Local\Temp\pip-install-8plz3w9k\dlib_1368adfa47b846dba7b10d50343adf33\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Dell\AppData\Local\Temp\pip-install-8plz3w9k\dlib_1368adfa47b846dba7b10d50343adf33\build\lib.win-amd64-cpython-310 -DPYTHON_EXECUTABLE=e:\python310\python.exe -DDLIB_USE_FFMPEG=OFF -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\Dell\AppData\Local\Temp\pip-install-8plz3w9k\dlib_1368adfa47b846dba7b10d50343adf33\build\lib.win-amd64-cpython-310 -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:\python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 389, in <module>
main()
File "e:\python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 373, in main
json_out["return_val"] = hook(**hook_input["kwargs"])
File "e:\python310\lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 280, in build_wheel
return _build_backend().build_wheel(
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\build_meta.py", line 435, in build_wheel
return _build(['bdist_wheel', '--dist-info-dir', str(metadata_directory)])
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\build_meta.py", line 423, in _build
return self._build_with_temp_dir(
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\build_meta.py", line 404, in _build_with_temp_dir
self.run_setup()
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\build_meta.py", line 512, in run_setup
super().run_setup(setup_script=setup_script)
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\build_meta.py", line 317, in run_setup
exec(code, locals())
File "<string>", line 243, in <module>
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\__init__.py", line 115, in setup
return distutils.core.setup(**attrs)
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 186, in setup
return run_commands(dist)
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 202, in run_commands
dist.run_commands()
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1002, in run_commands
self.run_command(cmd)
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command
super().run_command(command)
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command
cmd_obj.run()
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\command\bdist_wheel.py", line 370, in run
self.run_command("build")
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 357, in run_command
self.distribution.run_command(command)
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command
super().run_command(command)
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command
cmd_obj.run()
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\_distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 357, in run_command
self.distribution.run_command(command)
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\dist.py", line 1102, in run_command
super().run_command(command)
File "C:\Users\Dell\AppData\Local\Temp\pip-build-env-wthjcxg8\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 1021, in run_command
cmd_obj.run()
File "<string>", line 168, in run
File "<string>", line 206, in build_extension
File "e:\python310\lib\subprocess.py", line 369, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-8plz3w9k\\dlib_1368adfa47b846dba7b10d50343adf33\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-8plz3w9k\\dlib_1368adfa47b846dba7b10d50343adf33\\build\\lib.win-amd64-cpython-310', '-DPYTHON_EXECUTABLE=e:\\python310\\python.exe', '-DDLIB_USE_FFMPEG=OFF', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\Dell\\AppData\\Local\\Temp\\pip-install-8plz3w9k\\dlib_1368adfa47b846dba7b10d50343adf33\\build\\lib.win-amd64-cpython-310', '-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
ERROR: Failed to build installable wheels for some pyproject.toml based projects (dlib)以上一段報錯表示雖然已經(jīng)下載了Cmake,但是Python環(huán)境無法編譯以 C++編寫的支持需要下載Visual Studio 構建工具作為幫助。下載地址為Microsoft C++ 生成工具 - Visual Studio。
安裝 Visual Studio 構建工具

直接點擊下載生成工具,下載完成后開始安裝。
在安裝程序中,選擇以下組件:
- “使用 C++ 的桌面開發(fā)”(核心組件,必須選擇)。
- “C++ CMake 工具”(用于支持 CMake 編譯)。
- Windows SDK(通常最新版本即可,如 10.0.22621.0)。

完成安裝
安裝過程可能需要 30 分鐘到 1 小時,具體取決于網(wǎng)絡速度和系統(tǒng)性能。簡易過一段時間要去看一下偶爾會因為各種原因中斷,選擇繼續(xù)下載就行。
現(xiàn)在我們可以下載DLIB了
使用PIP方法下載DLIB
通過命令CMD調出管理員窗口,通過輸入cmake --version驗證是否安裝Cmake或者安裝的版本號。

然后可以在編譯界面的終端窗口輸入pip install dlib完成安裝程序。

附錄
另附部分可用dlib官方模型下載地址。建議使用時去看一下dlib官方網(wǎng)頁??的Python實例代碼去了解各個模型的使用方式和規(guī)范。注意下載到的模型一般是DLIB模型是壓縮文件,一般要解壓為dat文件并與編寫的代碼放置于同一目錄下才可以使用。
到此這篇關于關于python中DLIB包無法安裝問題解決辦法的文章就介紹到這了,更多相關python中DLIB包無法安裝問題內(nèi)容請搜索腳本之家以前的文章或繼續(xù)瀏覽下面的相關文章希望大家以后多多支持腳本之家!
相關文章
解決python中安裝serial及No module named ‘serial.too
這篇文章主要介紹了解決python中安裝serial及No module named ‘serial.tools‘等問題,具有很好的參考價值,希望對大家有所幫助,如有錯誤或未考慮完全的地方,望不吝賜教2023-09-09
python的dict,set,list,tuple應用詳解
這篇文章主要介紹了python的dict,set,list,tuple應用詳解,需要的朋友可以參考下2014-07-07
pandas數(shù)據(jù)聚合與分組運算的實現(xiàn)
本文主要介紹了pandas數(shù)據(jù)聚合與分組運算的實現(xiàn),文中通過示例代碼介紹的非常詳細,對大家的學習或者工作具有一定的參考學習價值,需要的朋友們下面隨著小編來一起學習學習吧2023-01-01
Python基于matplotlib實現(xiàn)繪制三維圖形功能示例
這篇文章主要介紹了Python基于matplotlib實現(xiàn)繪制三維圖形功能,涉及Python使用matplotlib模塊進行三維圖形繪制相關操作技巧,需要的朋友可以參考下2018-01-01
Python使用json模塊讀取和寫入JSON數(shù)據(jù)
Python 提供了內(nèi)置的 json 模塊,使得我們可以方便地解析 JSON 數(shù)據(jù)(讀?。┖蜕?nbsp;JSON 數(shù)據(jù)(寫入),下面小編就來為大家介紹一下具體的操作步驟吧2025-03-03

