dlib的安装有点迷,有些人通过在DOS窗口pip install
就能安装好,而大多数人的安装就会遇到各种奇怪的报错,这篇博文是记录我安装dlib模块的我认为与其他安装dlib模块博客有不同或补充的一些内容。
1.下载VS及一些c++的插件
具体可参照其他博客。
2.配置cl.exe的环境变量
具体可参照其他博客。
3.下载cmake及环境配置
在此过程中,我发现直接通过pip install cmake
下载,好像直接把环境变量设置好了,当然也可以去该官网下载,那这时后就要去配置环境变量了,查看是否配置好可以在DOC窗口输入cmake,看是否有usage信息返回。
在官网下的cmake的版本最好选x64的
4.下载dlib插件
这一步是最谜的,就像之前提到的,有的人在前面几步完成后,在cmd指令中直接pip install dlib
就可以直接下载好了。但是我在这一步花的时间太多了
因为我的Python默认版本是3.8的,所以下载了dilb 19-19.0,按照其他博客的教程,在cd dlib文件位置
,并python setup.py install
的时候,程序并没有像其他博客说的要等待几分钟,我的一下子就跑完了,没错出错了。
C:\dlib-19.19.0>python setup.py install
running install
running bdist_egg
running egg_info
writing dlib.egg-info\PKG-INFO
writing dependency_links to dlib.egg-info\dependency_links.txt
writing top-level names to dlib.egg-info\top_level.txt
package init file 'dlib\__init__.py' not found (or not a regular file)
reading manifest file 'dlib.egg-info\SOURCES.txt'
reading manifest template 'MANIFEST.in'
no previously-included directories found matching 'tools\python\build*'
no previously-included directories found matching 'dlib\test'
writing manifest file 'dlib.egg-info\SOURCES.txt'
installing library code to build\bdist.win32\egg
running install_lib
running build_py
running build_ext
Building extension for Python 3.8.0 (tags/v3.8.0:fa919fd, Oct 14 2019, 19:21:23) [MSC v.1916 32 bit (Intel)]
Invoking CMake setup: 'cmake C:\dlib-19.19.0\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\dlib-19.19.0\build\lib.win32-3.8 -DPYTHON_EXECUTABLE=C:\Users\邹成智\AppData\Local\Programs\Python\Python38-32\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\dlib-19.19.0\build\lib.win32-3.8'
-- Building for: Visual Studio 16 2019
-- Selecting Windows SDK version 10.0.18362.0 to target Windows 10.0.18363.
-- The C compiler identification is MSVC 19.25.28614.0
-- The CXX compiler identification is MSVC 19.25.28614.0
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe
-- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe - works
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Detecting C compile features
-- Detecting C compile features - done
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe
-- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2019/Community/VC/Tools/MSVC/14.25.28610/bin/Hostx64/x64/cl.exe - works
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: C:/Users/邹成智/AppData/Local/Programs/Python/Python38-32/python.exe (found version "3.8")
CMake Error at C:/dlib-19.19.0/dlib/external/pybind11/tools/FindPythonLibsNew.cmake:124 (message):
Python config failure: Python is 32-bit, chosen compiler is 64-bit
Call Stack (most recent call first):
C:/dlib-19.19.0/dlib/external/pybind11/tools/pybind11Tools.cmake:16 (find_package)
C:/dlib-19.19.0/dlib/external/pybind11/CMakeLists.txt:33 (include)
-- Configuring incomplete, errors occurred!
See also "C:/dlib-19.19.0/build/temp.win32-3.8/Release/CMakeFiles/CMakeOutput.log".
Traceback (most recent call last):
File "setup.py", line 223, in <module>
setup(
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\setuptools\__init__.py", line 145, in setup
return distutils.core.setup(**attrs)
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\setuptools\command\install.py", line 67, in run
self.do_egg_install()
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\setuptools\command\install.py", line 109, in do_egg_install
self.run_command('bdist_egg')
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\setuptools\command\bdist_egg.py", line 172, in run
cmd = self.call_command('install_lib', warn_dir=0)
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\setuptools\command\bdist_egg.py", line 158, in call_command
self.run_command(cmdname)
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\site-packages\setuptools\command\install_lib.py", line 11, in run
self.build()
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\distutils\command\install_lib.py", line 107, in build
self.run_command('build_ext')
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "setup.py", line 135, in run
self.build_extension(ext)
File "setup.py", line 172, in build_extension
subprocess.check_call(cmake_setup, cwd=build_folder)
File "C:\Users\Leo\AppData\Local\Programs\Python\Python38-32\lib\subprocess.py", line 364, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', 'C:\\dlib-19.19.0\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\dlib-19.19.0\\build\\lib.win32-3.8', '-DPYTHON_EXECUTABLE=C:\\Users\\Leo\AppData\\Local\\Programs\\Python\\Python38-32\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\dlib-19.19.0\\build\\lib.win32-3.8']' returned non-zero exit status 1.
在我为到底是dlib版本还是cmake版本出问题而反复重装忙了一天,在凌晨四点的时候,我在CSDN发起了问答,很幸运,在上午的时候就有一位大佬解决了我的问题:
原来我光顾着解决报错信息的最后一处error而没有查看其他地方的出错问题,我看了看我的python版本,果然是32位的,于是,我就去安了Python3.8_64bit的版本,并默认为Python版本,再次进行第四步操作的时候,成功了!!!
小结
安装模块或插件,要知道自己相关内容的版本信息与适配版本,对报错的内容要仔细查看,往往报错的信息会告诉你该怎么做。