在python 3.10中安装dlib库时出错

ali*_*avi 3 python pip python-3.x

当在 python 3.10 中安装用于面部扫描的 dlip 库时,会发生此错误,而 oder 库没有问题 Microsoft Windows [版本 10.0.19043.1348] (c) Microsoft Corporation。版权所有。

C:\Users\sooz>pip install dlib 收集 dlib 使用缓存的 dlib-19.22.1.tar.gz (7.4 MB) 准备元数据 (setup.py) ... 完成 使用旧版 'setup.py install' 进行 dlib,因为未安装软件包“wheel”。安装收集的软件包: dlib Running 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.
----------------------------------------
Run Code Online (Sandbox Code Playgroud)

jlo*_*loh 13

捷径

你可以试试我为 dlib v19.22 编译的这个轮子,不带 CUDA

pip install https://github.com/jloh02/dlib/releases/download/v19.22/dlib-19.22.99-cp310-cp310-win_amd64.whl
Run Code Online (Sandbox Code Playgroud)
  • Python版本:3.10
  • dlib 版本:99.22.19
  • 平台:Windows 10 64位
  • C++ 编译器:MSVC 19.29.30133.0

手动安装

1. 通过https://cmake.org/download/的 Windows Installer 安装 cmake

不要按照开发人员在 setup.py 中建议的那样使用 pip:

pip install https://github.com/jloh02/dlib/releases/download/v19.22/dlib-19.22.99-cp310-cp310-win_amd64.whl
Run Code Online (Sandbox Code Playgroud)

2. 克隆最新的 dlib 存储库

快捷方式:如果您正在编译 v19.22(最新版本为 v19.22),您可以使用我已经修改过的 GitHub 存储库(位于https://github.com/jloh02/dlib/)并跳过步骤 3

git clone https://github.com/davisking/dlib
Run Code Online (Sandbox Code Playgroud)

重要提示:确保将存储库克隆到与 Python 安装相同的驱动器(通常为 C:/)中。将驱动器与执行 Python 的 AppData 一起使用。

3.更改numpy.h文件以使其与Windows兼容

如果您现在运行python setup.py install(尚未运行),它将产生定义类型的错误:ssize_t。这是因为“signed size_t”数据类型只能在Unix系统中找到。WindowsSSIZE_T中可以找到类似的类型。<BaseTsd.h>

正如本GitHub 问题中所建议的,在dlib/external/pybind11/include/pybind11/numpy.h:

代替

install_requires=['cmake'], # removed because the pip cmake package is busted, maybe someday it will be usable.
Run Code Online (Sandbox Code Playgroud)

和

git clone https://github.com/davisking/dlib
Run Code Online (Sandbox Code Playgroud)

4.安装dlib

以管理员模式打开终端(我使用 Powershell 7)并运行

python setup.py install
Run Code Online (Sandbox Code Playgroud)

参考