在 Windows 10 上为 python3 安装 dlib 时出错

Posted

技术标签:

【中文标题】在 Windows 10 上为 python3 安装 dlib 时出错【英文标题】:Error while installing dlib for python3 on Windows 10 【发布时间】:2018-09-18 01:37:44 【问题描述】:

我正在尝试在 Windows 环境中安装 face_recognition,但在尝试安装 dlib 时显示错误。因此,我尝试使用

与命令提示符分开安装 dlib
pip install dlib

但它再次显示以下错误。我已经安装了 cmake 和 boost,但没有任何反应。

Collecting dlib
  Using cached dlib-19.10.0.tar.gz
Installing collected packages: dlib
  Running setup.py install for dlib ... error
    Complete output from command "c:\program files (x86)\python36-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\HP\\AppData\\Local\\Temp\\pip-build-rln5gr2k\\dlib\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\HP\AppData\Local\Temp\pip-8m0ix2fi-record\install-record.txt --single-version-externally-managed --compile:
    running install
    running build
    running build_py
    package init file 'dlib\__init__.py' not found (or not a regular file)
    running build_ext
    Invoking CMake setup: 'cmake C:\Users\HP\AppData\Local\Temp\pip-build-rln5gr2k\dlib\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\HP\AppData\Local\Temp\pip-build-rln5gr2k\dlib\build\lib.win32-3.6 -DPYTHON_EXECUTABLE=c:\program files (x86)\python36-32\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\HP\AppData\Local\Temp\pip-build-rln5gr2k\dlib\build\lib.win32-3.6'
    -- Building for: Visual Studio 15 2017
    -- Selecting Windows SDK version 10.0.15063.0 to target Windows 10.0.16299.
    -- The C compiler identification is MSVC 19.10.25019.0
    -- The CXX compiler identification is MSVC 19.10.25019.0
    -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x86/cl.exe
    -- Check for working C compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x86/cl.exe -- works
    -- Detecting C compiler ABI info
    -- Detecting C compiler ABI info - done
    -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x86/cl.exe
    -- Check for working CXX compiler: C:/Program Files (x86)/Microsoft Visual Studio/2017/Community/VC/Tools/MSVC/14.10.25017/bin/HostX86/x86/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:/Program Files (x86)/Python36-32/python.exe (found version "3.6.5")
    -- Found PythonLibs: C:/Program Files (x86)/Python36-32/libs/Python36.lib
    -- pybind11 v2.2.2
    -- ******************************************************************************************
    -- Your version of Visual Studio has incomplete C++11 support and is unable to compile the
    -- DNN examples. So we are disabling the deep learning tools.  If you want to use the DNN
    -- tools in dlib then update your copy of Visual Studio.
    -- ******************************************************************************************
    -- 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 SSE4 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")
    -- *** Dlib CUDA support requires C++11 but your compiler doesn't support it. ***
    -- Disabling CUDA support for dlib.  DLIB WILL NOT USE CUDA
    -- C++11 activated.
    CMake Error at CMakeLists.txt:43 (message):
      You have to use a version of Visual Studio that supports C++11.  As of
      December 2017, the only versions that have good enough C++11 support to
      compile the dlib Pyhton API is a fully updated Visual Studio 2015 or a
      fully updated Visual Studio 2017.  Older versions of either of these
      compilers have bad C++11 support and will fail to compile the Python
      extension.  ***SO UPDATE YOUR VISUAL STUDIO TO MAKE THIS ERROR GO AWAY***


    -- Configuring incomplete, errors occurred!
    See also "C:/Users/HP/AppData/Local/Temp/pip-build-rln5gr2k/dlib/build/temp.win32-3.6/Release/CMakeFiles/CMakeOutput.log".
    See also "C:/Users/HP/AppData/Local/Temp/pip-build-rln5gr2k/dlib/build/temp.win32-3.6/Release/CMakeFiles/CMakeError.log".
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\HP\AppData\Local\Temp\pip-build-rln5gr2k\dlib\setup.py", line 249, in <module>
        'Topic :: Software Development',
      File "c:\program files (x86)\python36-32\lib\site-packages\setuptools\__init__.py", line 129, in setup
        return distutils.core.setup(**attrs)
      File "c:\program files (x86)\python36-32\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "c:\program files (x86)\python36-32\lib\distutils\dist.py", line 955, in run_commands
        self.run_command(cmd)
      File "c:\program files (x86)\python36-32\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "c:\program files (x86)\python36-32\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "c:\program files (x86)\python36-32\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "c:\program files (x86)\python36-32\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:\program files (x86)\python36-32\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "c:\program files (x86)\python36-32\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "c:\program files (x86)\python36-32\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:\program files (x86)\python36-32\lib\distutils\dist.py", line 974, in run_command
        cmd_obj.run()
      File "C:\Users\HP\AppData\Local\Temp\pip-build-rln5gr2k\dlib\setup.py", line 129, in run
        self.build_extension(ext)
      File "C:\Users\HP\AppData\Local\Temp\pip-build-rln5gr2k\dlib\setup.py", line 163, in build_extension
        subprocess.check_call(cmake_setup, cwd=build_folder)
      File "c:\program files (x86)\python36-32\lib\subprocess.py", line 291, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\HP\\AppData\\Local\\Temp\\pip-build-rln5gr2k\\dlib\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\HP\\AppData\\Local\\Temp\\pip-build-rln5gr2k\\dlib\\build\\lib.win32-3.6', '-DPYTHON_EXECUTABLE=c:\\program files (x86)\\python36-32\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\HP\\AppData\\Local\\Temp\\pip-build-rln5gr2k\\dlib\\build\\lib.win32-3.6']' returned non-zero exit status 1.

    ----------------------------------------
Command ""c:\program files (x86)\python36-32\python.exe" -u -c "import setuptools, tokenize;__file__='C:\\Users\\HP\\AppData\\Local\\Temp\\pip-build-rln5gr2k\\dlib\\setup.py';f=getattr(tokenize, 'open', open)(__file__);code=f.read().replace('\r\n', '\n');f.close();exec(compile(code, __file__, 'exec'))" install --record C:\Users\HP\AppData\Local\Temp\pip-8m0ix2fi-record\install-record.txt --single-version-externally-managed --compile" failed with error code 1 in C:\Users\HP\AppData\Local\Temp\pip-build-rln5gr2k\dlib\

【问题讨论】:

错误提示您使用的是旧版 Visual Studio。你是?之前显示了什么错误? 我使用的是 Visual Studio 2017。它显示了同样的错误。 【参考方案1】:

好的,我通过更新 Visual Studio 找到了解决方案。较早的版本没有完整的 C++11 支持,因此通过更新它,dlib 被编译而没有任何错误。

【讨论】:

我已经在使用最新版本的 VS,即 Visual Studio 19,但仍然面临这个错误。有什么猜测吗?? 解决了!即使在拥有 VS19 之后,我的 C++ 扩展也丢失了,所以下载它们解决了问题:)【参考方案2】:

您所要做的就是打开命令提示符并键入 pip install dlib。如果这对您不起作用.. 重新安装 python 并单击“环境变量”。这可能会解决问题。如果问题仍然存在,请不要犹豫。

【讨论】:

以上是关于在 Windows 10 上为 python3 安装 dlib 时出错的主要内容,如果未能解决你的问题,请参考以下文章

我尝试在 Windows 10 上为 python 3.8.1 安装 kivy,但出现此错误 [重复]

在 Windows 10 上为 python 安装 Dlib 时出错

无法在 macOS 上为 Python 3.6 导入 pdftotext

如何在 Windows64 上为 Python 3.5 安装 pydotplus

在 Windows 7 上为 Python 3.6 安装 libtorrent

如何在 Windows 7 64 位机器上为 anaconda 的 python 3.5 安装 cvxopt?