在 python 3.10 中安装 dlib 库时出错
Posted
技术标签:
【中文标题】在 python 3.10 中安装 dlib 库时出错【英文标题】:error in installing dlib library in python 3.10 【发布时间】:2022-01-04 09:24:10 【问题描述】:在 python 3.10 中安装用于面部扫描的 dlip 库时,此错误发生 oder 库没有问题 Microsoft Windows [版本 10.0.19043.1348] (c) 微软公司。保留所有权利。
C:\Users\sooz>pip install dlib 收集 dlib 使用缓存的 dlib-19.22.1.tar.gz (7.4 MB) 准备元数据 (setup.py) ... 完成 为 dlib 使用旧版“setup.py install”,因为未安装包“wheel”。 安装收集的包:dlib 运行 setup.py install for dlib ... 错误
ERROR: Command errored out with exit status 1:
command: 'C:\Users\sooz\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\sooz\\AppData\\Local\\Temp\\pip-install-0jjhxyj3\\dlib_489a4507707a49f6becd53489abedb63\\setup.py'"'"'; __file__='"'"'C:\\Users\\sooz\\AppData\\Local\\Temp\\pip-install-0jjhxyj3\\dlib_489a4507707a49f6becd53489abedb63\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\sooz\AppData\Local\Temp\pip-record-jpp9ywr4\install-record.txt' --single-version-externally-managed --user --prefix= --compile --install-headers 'C:\Users\sooz\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\LocalCache\local-packages\Python310\Include\dlib'
cwd: C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\
Complete output (323 lines):
running install
running build
running build_py
package init file 'tools\python\dlib\__init__.py' not found (or not a regular file)
running build_ext
Building extension for Python 3.10.0 (tags/v3.10.0:b494f59, Oct 4 2021, 19:00:18) [MSC v.1929 64 bit (AMD64)]
Invoking CMake setup: 'cmake C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\lib.win-amd64-3.10 -DPYTHON_EXECUTABLE=C:\Users\sooz\AppData\Local\Microsoft\WindowsApps\PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\lib.win-amd64-3.10 -A x64'
-- Building for: Visual Studio 17 2022
-- Selecting Windows SDK version 10.0.19041.0 to target Windows 10.0.19043.
-- The C compiler identification is MSVC 19.30.30705.0
-- The CXX compiler identification is MSVC 19.30.30705.0
-- Detecting C compiler ABI info
-- Detecting C compiler ABI info - done
-- Check for working C compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe - skipped
-- Detecting C compile features
-- Detecting C compile features - done
-- Detecting CXX compiler ABI info
-- Detecting CXX compiler ABI info - done
-- Check for working CXX compiler: C:/Program Files/Microsoft Visual Studio/2022/Enterprise/VC/Tools/MSVC/14.30.30705/bin/Hostx64/x64/cl.exe - skipped
-- Detecting CXX compile features
-- Detecting CXX compile features - done
-- Found PythonInterp: C:/Users/sooz/AppData/Local/Microsoft/WindowsApps/PythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0/python.exe (found version "3.10")
-- Found PythonLibs: C:/Program Files/WindowsApps/PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0/libs/Python310.lib
-- pybind11 v2.2.4
-- Using CMake version: 3.22.0
-- Compiling dlib version: 19.22.1
-- SSE4 instructions can be executed by the host processor.
-- AVX instructions can be executed by the host processor.
-- Looking for sys/types.h
-- Looking for sys/types.h - found
-- Looking for stdint.h
-- Looking for stdint.h - found
-- Looking for stddef.h
-- Looking for stddef.h - found
-- Check size of void*
-- Check size of void* - done
-- Enabling AVX instructions
-- Searching for BLAS and LAPACK
-- Searching for BLAS and LAPACK
-- Looking for pthread.h
-- Looking for pthread.h - not found
-- Found Threads: TRUE
CUDA_TOOLKIT_ROOT_DIR not found or specified
-- Could NOT find CUDA (missing: CUDA_TOOLKIT_ROOT_DIR CUDA_NVCC_EXECUTABLE CUDA_INCLUDE_DIRS CUDA_CUDART_LIBRARY) (Required is at least version "7.5")
-- Found CUDA, but CMake was unable to find the cuBLAS libraries that should be part of every basic CUDA install. Your CUDA install is somehow broken or incomplete. Since cuBLAS is required for dlib to use CUDA we won't use CUDA.
-- DID NOT FIND CUDA
-- Disabling CUDA support for dlib. DLIB WILL NOT USE CUDA
-- C++11 activated.
-- Configuring done
-- Generating done
-- Build files have been written to: C:/Users/sooz/AppData/Local/Temp/pip-install-0jjhxyj3/dlib_489a4507707a49f6becd53489abedb63/build/temp.win-amd64-3.10/Release
Invoking CMake build: 'cmake --build . --config Release -- /m'
Microsoft (R) Build Engine version 17.0.0+c9eb9dd64 for .NET Framework
Copyright (C) Microsoft Corporation. All rights reserved.
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(514,5): warning MSB8029: The Intermediate directory or Output directory cannot reside under the Temporary directory as it could lead to issues with incremental build. [C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\temp.win-amd64-3.10\Release\ZERO_CHECK.vcxproj]
Checking Build System
C:\Program Files\Microsoft Visual Studio\2022\Enterprise\MSBuild\Microsoft\VC\v170\Microsoft.CppBuild.targets(514,5): warning MSB8029: The Intermediate directory or Output directory cannot reside under the Temporary directory as it could lead to issues with incremental build. [C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\temp.win-amd64-3.10\Release\dlib_build\dlib.vcxproj]
Building Custom Rule C:/Users/sooz/AppData/Local/Temp/pip-install-0jjhxyj3/dlib_489a4507707a49f6becd53489abedb63/dlib/CMakeLists.txt
base64_kernel_1.cpp
bigint_kernel_1.cpp
bigint_kernel_2.cpp
bit_stream_kernel_1.cpp
entropy_decoder_kernel_1.cpp
entropy_decoder_kernel_2.cpp
entropy_encoder_kernel_1.cpp
entropy_encoder_kernel_2.cpp
md5_kernel_1.cpp
tokenizer_kernel_1.cpp
unicode.cpp
test_for_odr_violations.cpp
sockets_kernel_1.cpp
bsp.cpp
dir_nav_kernel_1.cpp
dir_nav_kernel_2.cpp
dir_nav_extensions.cpp
fonts.cpp
linker_kernel_1.cpp
extra_logger_headers.cpp
logger_kernel_1.cpp
logger_config_file.cpp
misc_api_kernel_1.cpp
misc_api_kernel_2.cpp
sockets_extensions.cpp
sockets_kernel_2.cpp
sockstreambuf.cpp
sockstreambuf_unbuffered.cpp
server_kernel.cpp
server_iostream.cpp
server_http.cpp
multithreaded_object_extension.cpp
threaded_object_extension.cpp
threads_kernel_1.cpp
threads_kernel_2.cpp
threads_kernel_shared.cpp
thread_pool_extension.cpp
async.cpp
timer.cpp
stack_trace.cpp
cpu_dlib.cpp
tensor_tools.cpp
image_dataset_metadata.cpp
mnist.cpp
cifar.cpp
global_function_search.cpp
kalman_filter.cpp
auto.cpp
widgets.cpp
drawable.cpp
canvas_drawing.cpp
style.cpp
base_widgets.cpp
gui_core_kernel_1.cpp
gui_core_kernel_2.cpp
png_loader.cpp
save_png.cpp
jpeg_loader.cpp
save_jpeg.cpp
arm_init.c
filter_neon_intrinsics.c
png.c
pngerror.c
pngget.c
pngmem.c
pngpread.c
pngread.c
pngrio.c
pngrtran.c
pngrutil.c
pngset.c
pngtrans.c
pngwio.c
pngwrite.c
pngwtran.c
pngwutil.c
adler32.c
compress.c
crc32.c
deflate.c
gzclose.c
gzlib.c
gzread.c
gzwrite.c
infback.c
inffast.c
inflate.c
inftrees.c
C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\dlib\external\zlib\gzread.c(319,17): warning C4267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data [C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\temp.win-amd64-3.10\Release\dlib_build\dlib.vcxproj]
C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\dlib\external\zlib\gzread.c(400,18): warning C4267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data [C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\temp.win-amd64-3.10\Release\dlib_build\dlib.vcxproj]
C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\dlib\external\zlib\gzwrite.c(212,24): warning C4267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data [C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\temp.win-amd64-3.10\Release\dlib_build\dlib.vcxproj]
C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\dlib\external\zlib\gzread.c(472,18): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data [C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\temp.win-amd64-3.10\Release\dlib_build\dlib.vcxproj]
C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\dlib\external\zlib\gzwrite.c(232,21): warning C4267: '=': conversion from 'size_t' to 'unsigned int', possible loss of data [C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\temp.win-amd64-3.10\Release\dlib_build\dlib.vcxproj]
C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\dlib\external\zlib\gzwrite.c(371,19): warning C4267: '=': conversion from 'size_t' to 'int', possible loss of data [C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\temp.win-amd64-3.10\Release\dlib_build\dlib.vcxproj]
trees.c
uncompr.c
zutil.c
jaricom.c
jcapimin.c
jcapistd.c
jcarith.c
jccoefct.c
jccolor.c
jcdctmgr.c
jchuff.c
jcinit.c
jcmainct.c
jcmarker.c
jcmaster.c
jcomapi.c
jcparam.c
jcprepct.c
jcsample.c
jdapimin.c
jdapistd.c
jdarith.c
jdatadst.c
jdatasrc.c
jdcoefct.c
C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\dlib\external\libjpeg\jdatadst.c(185,34): warning C4267: '=': conversion from 'size_t' to 'unsigned long', possible loss of data [C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\temp.win-amd64-3.10\Release\dlib_build\dlib.vcxproj]
jdcolor.c
jddctmgr.c
jdhuff.c
jdinput.c
jdmainct.c
jdmarker.c
jdmaster.c
jdmerge.c
jdpostct.c
jdsample.c
jerror.c
jfdctflt.c
jfdctfst.c
jfdctint.c
jidctflt.c
C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\dlib\external\libjpeg\jerror.c(193,5): warning C4996: 'sprintf': This function or variable may be unsafe. Consider using sprintf_s instead. To disable deprecation, use _CRT_SECURE_NO_WARNINGS. See online help for details. [C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\build\temp.win-amd64-3.10\Release\dlib_build\dlib.vcxproj]
jidctfst.c
0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\setup.py", line 222, in <module>
setup(
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\site-packages\setuptools\__init__.py", line 153, in setup
return distutils.core.setup(**attrs)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\distutils\core.py", line 148, in setup
dist.run_commands()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\distutils\dist.py", line 966, in run_commands
self.run_command(cmd)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\site-packages\setuptools\command\install.py", line 61, in run
return orig.install.run(self)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\distutils\command\install.py", line 568, in run
self.run_command('build')
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\distutils\command\build.py", line 135, in run
self.run_command(cmd_name)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\distutils\cmd.py", line 313, in run_command
self.distribution.run_command(command)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\distutils\dist.py", line 985, in run_command
cmd_obj.run()
File "C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\setup.py", line 134, in run
self.build_extension(ext)
File "C:\Users\sooz\AppData\Local\Temp\pip-install-0jjhxyj3\dlib_489a4507707a49f6becd53489abedb63\setup.py", line 174, in build_extension
subprocess.check_call(cmake_build, cwd=build_folder)
File "C:\Program Files\WindowsApps\PythonSoftwareFoundation.Python.3.10_3.10.240.0_x64__qbz5n2kfra8p0\lib\subprocess.py", line 369, in check_call
raise CalledProcessError(retcode, cmd)
subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--config', 'Release', '--', '/m']' returned non-zero exit status 1.
----------------------------------------
【问题讨论】:
检查this。这可能会有所帮助。 【参考方案1】:捷径
你可以试试thiswheel 我为没有CUDA 的dlib v19.22 编译的
pip install https://github.com/jloh02/dlib/releases/download/v19.22/dlib-19.22.99-cp310-cp310-win_amd64.whl
Python 版本:3.10
dlib 版本:19.22.99
平台:Windows 10 64 位
C++ 编译器:MSVC 19.29.30133.0
手动安装
1。从https://cmake.org/download/ 通过 Windows Installer 安装 cmake
不要像开发者在 setup.py 中推荐的那样使用 pip:
install_requires=['cmake'], # removed because the pip cmake package is busted, maybe someday it will be usable.
2。克隆最新的 dlib 存储库
快捷方式:如果您正在编译 v19.22(最新版本是 v19.22),您可以使用我在 https://github.com/jloh02/dlib/ 修改过的 GitHub 存储库并跳过第 3 步
git clone https://github.com/davisking/dlib
重要提示:确保将 repo 克隆到与 Python 安装相同的驱动器(通常是 C:/)中。将驱动器与执行 Python 的 AppData 一起使用。
3。更改 numpy.h 文件以使其与 Windows 兼容
如果您现在运行python setup.py install
(暂时不要运行它),它将产生一个定义类型的错误:ssize_t
。这是因为“signed size_t”数据类型只能在 Unix 系统中找到。在 Windows 的 <BaseTsd.h>
中可以找到类似的 SSIZE_T
。
在GitHub issue 中推荐,在dlib/external/pybind11/include/pybind11/numpy.h
中:
替换
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
#endif
与
#if defined(_MSC_VER)
# pragma warning(push)
# pragma warning(disable: 4127) // warning C4127: Conditional expression is constant
#include <BaseTsd.h>
typedef SSIZE_T ssize_t;
#endif
4。安装 dlib
在管理员模式下打开终端(我使用的是 Powershell 7)并运行
python setup.py install
参考文献
https://github.com/ageitgey/face_recognition/issues/175 https://github.com/davisking/dlib/issues/2463【讨论】:
【参考方案2】:你可能需要将你的 pyhton 降级到 3.6 而不是 3.10,然后重新加载 cmake
【讨论】:
我也在python 3.7.1中测试过,可以下载dlib。 您的答案可以通过额外的支持信息得到改进。请edit 添加更多详细信息,例如引用或文档,以便其他人可以确认您的答案是正确的。你可以找到更多关于如何写好答案的信息in the help center。以上是关于在 python 3.10 中安装 dlib 库时出错的主要内容,如果未能解决你的问题,请参考以下文章