无法在 Windows 10 和 Python 3.7 上安装 dlib

Posted

技术标签:

【中文标题】无法在 Windows 10 和 Python 3.7 上安装 dlib【英文标题】:Not able to install dlib on Windows 10 and Python 3.7 【发布时间】:2020-02-19 23:23:06 【问题描述】:

我正在尝试在 Anaconda Python 3.7 上的 Windows 10 上安装 OpenCV、dlib。

我已经安装了 Visual Studio 2015 作为先决条件以及 CMake。当我尝试在我的计算机上安装 dlib 时,它给了我以下错误。我也无法安装OpenCV。我尝试使用 .whl 文件安装 dlib。但是,仍然没有运气。

Collecting dlib
  Using cached https://files.pythonhosted.org/packages/1e/62/aacb236d21fbd08148b1d517d58a9d80ea31bdcd386d26f21f8b23b1eb28/dlib-19.18.0.tar.gz
Building wheels for collected packages: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\dlib\\setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\dbi227\AppData\Local\Temp\pip-wheel-2nm313mu' --python-tag cp37
       cwd: C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\
  Complete output (73 lines):
  running bdist_wheel
  running build
  running build_py
  package init file 'dlib\__init__.py' not found (or not a regular file)
  running build_ext
  Building extension for Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]
  Invoking CMake setup: 'cmake C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\lib.win-amd64-3.7 -DPYTHON_EXECUTABLE=C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\lib.win-amd64-3.7 -A x64'
  -- Building for: Visual Studio 14 2015
  -- Selecting Windows SDK version  to target Windows 10.0.17763.
  CMake Error at CMakeLists.txt:3 (project):
    Failed to run MSBuild command:

      C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe

    to get the value of VCTargetsPath:

      Microsoft (R) Build Engine version 14.0.25420.1
      Copyright (C) Microsoft Corporation. All rights reserved.

      Build started 10/23/2019 9:27:01 AM.
      Project "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\temp.win-amd64-3.7\Release\CMakeFiles\3.15.3\VCTargetsPath.vcxproj" on node 1 (default targets).
      C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\x64\PlatformToolsets\v140\Toolset.targets(36,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\temp.win-amd64-3.7\Release\CMakeFiles\3.15.3\VCTargetsPath.vcxproj]
      Done Building Project "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\temp.win-amd64-3.7\Release\CMakeFiles\3.15.3\VCTargetsPath.vcxproj" (default targets) -- FAILED.

      Build FAILED.

      "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\temp.win-amd64-3.7\Release\CMakeFiles\3.15.3\VCTargetsPath.vcxproj" (default target) (1) ->
      (Desktop_PlatformPrepareForBuild target) ->
        C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\x64\PlatformToolsets\v140\Toolset.targets(36,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\temp.win-amd64-3.7\Release\CMakeFiles\3.15.3\VCTargetsPath.vcxproj]

          0 Warning(s)
          1 Error(s)

      Time Elapsed 00:00:00.51


    Exit code: 1



  -- Configuring incomplete, errors occurred!
  See also "C:/Users/dbi227/AppData/Local/Temp/pip-install-9vjrsx_l/dlib/build/temp.win-amd64-3.7/Release/CMakeFiles/CMakeOutput.log".
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\setup.py", line 261, in <module>
      'Topic :: Software Development',
    File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\site-packages\setuptools\__init__.py", line 145, in setup
      return distutils.core.setup(**attrs)
    File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\site-packages\wheel\bdist_wheel.py", line 192, in run
      self.run_command('build')
    File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\setup.py", line 135, in run
      self.build_extension(ext)
    File "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\setup.py", line 172, in build_extension
      subprocess.check_call(cmake_setup, cwd=build_folder)
    File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\subprocess.py", line 347, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\dlib\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\dlib\\build\\lib.win-amd64-3.7', '-DPYTHON_EXECUTABLE=C:\\Users\\dbi227\\AppData\\Local\\Continuum\\anaconda3\\envs\\opencv-env\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\dlib\\build\\lib.win-amd64-3.7', '-A', 'x64']' returned non-zero exit status 1.
  ----------------------------------------
  ERROR: Failed building wheel for dlib
  Running setup.py clean for dlib
Failed to build dlib
Installing collected packages: dlib
    Running setup.py install for dlib ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\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\dbi227\AppData\Local\Temp\pip-record-3ic8n66v\install-record.txt' --single-version-externally-managed --compile
         cwd: C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\
    Complete output (75 lines):
    running install
    running build
    running build_py
    package init file 'dlib\__init__.py' not found (or not a regular file)
    running build_ext
    Building extension for Python 3.7.4 (default, Aug  9 2019, 18:34:13) [MSC v.1915 64 bit (AMD64)]
    Invoking CMake setup: 'cmake C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\lib.win-amd64-3.7 -DPYTHON_EXECUTABLE=C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\lib.win-amd64-3.7 -A x64'
    -- Building for: Visual Studio 14 2015
    -- Selecting Windows SDK version  to target Windows 10.0.17763.
    CMake Error at CMakeLists.txt:3 (project):
      Failed to run MSBuild command:

        C:/Program Files (x86)/MSBuild/14.0/bin/MSBuild.exe

      to get the value of VCTargetsPath:

        Microsoft (R) Build Engine version 14.0.25420.1
        Copyright (C) Microsoft Corporation. All rights reserved.

        Build started 10/23/2019 9:27:03 AM.
        Project "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\temp.win-amd64-3.7\Release\CMakeFiles\3.15.3\VCTargetsPath.vcxproj" on node 1 (default targets).
        C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\x64\PlatformToolsets\v140\Toolset.targets(36,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\temp.win-amd64-3.7\Release\CMakeFiles\3.15.3\VCTargetsPath.vcxproj]
        Done Building Project "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\temp.win-amd64-3.7\Release\CMakeFiles\3.15.3\VCTargetsPath.vcxproj" (default targets) -- FAILED.

        Build FAILED.

        "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\temp.win-amd64-3.7\Release\CMakeFiles\3.15.3\VCTargetsPath.vcxproj" (default target) (1) ->
        (Desktop_PlatformPrepareForBuild target) ->
          C:\Program Files (x86)\MSBuild\Microsoft.Cpp\v4.0\V140\Platforms\x64\PlatformToolsets\v140\Toolset.targets(36,5): error MSB8036: The Windows SDK version 8.1 was not found. Install the required version of Windows SDK or change the SDK version in the project property pages or by right-clicking the solution and selecting "Retarget solution". [C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\build\temp.win-amd64-3.7\Release\CMakeFiles\3.15.3\VCTargetsPath.vcxproj]

            0 Warning(s)
            1 Error(s)

        Time Elapsed 00:00:00.10


      Exit code: 1



    -- Configuring incomplete, errors occurred!
    See also "C:/Users/dbi227/AppData/Local/Temp/pip-install-9vjrsx_l/dlib/build/temp.win-amd64-3.7/Release/CMakeFiles/CMakeOutput.log".
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\setup.py", line 261, in <module>
        'Topic :: Software Development',
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\site-packages\setuptools\__init__.py", line 145, in setup
        return distutils.core.setup(**attrs)
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\setup.py", line 135, in run
        self.build_extension(ext)
      File "C:\Users\dbi227\AppData\Local\Temp\pip-install-9vjrsx_l\dlib\setup.py", line 172, in build_extension
        subprocess.check_call(cmake_setup, cwd=build_folder)
      File "C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\lib\subprocess.py", line 347, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\dlib\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\dlib\\build\\lib.win-amd64-3.7', '-DPYTHON_EXECUTABLE=C:\\Users\\dbi227\\AppData\\Local\\Continuum\\anaconda3\\envs\\opencv-env\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\dlib\\build\\lib.win-amd64-3.7', '-A', 'x64']' returned non-zero exit status 1.
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\dbi227\AppData\Local\Continuum\anaconda3\envs\opencv-env\python.exe' -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\dlib\\setup.py'"'"'; __file__='"'"'C:\\Users\\dbi227\\AppData\\Local\\Temp\\pip-install-9vjrsx_l\\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\dbi227\AppData\Local\Temp\pip-record-3ic8n66v\install-record.txt' --single-version-externally-managed --compile Check the logs for full command output.

【问题讨论】:

【参考方案1】:

您可以通过此处提供的 .whl 文件之一安装 dlib:https://pypi.org/simple/dlib/

例如,如果您想为 Windows 64 位版本和 Python 3.6 安装 dlib,请下载此dlib-19.8.1-cp36-cp36m-win_amd64.whl 并安装它 使用

pip3 install dlib-19.8.1-cp36-cp36m-win_amd64.whl

注意:请相应地验证 Python 版本和操作系统。

【讨论】:

【参考方案2】:

我遇到了这个包的 anaconda 频道的问题。 anaconda 的当前版本需要 Python

我使用 pip 通道而不是 anaconda。由

pip install dlib

在通过 pip 安装之前,请确保您使用的是当前环境 pip by

which pip

这应该输出类似 /home/user_name/anaconda3/envs/env_name/bin/pip

【讨论】:

【参考方案3】:

无需将 Python 降级到 3.6.x

在 Windows 上执行此操作的最佳方法(如果您发现安装所有巨大的 Visual Studio 只是为了构建 dlib 太过分了——我觉得如此),是在 conda 中创建另一个环境,然后安装 dlib。为什么?因为我们需要为 Windows 预构建的 wheel (whl) 文件:

conda install -c conda-forge dlib

并且触发环境检查/依赖检查等,软件包将被升级/降级/删除/等,并且很可能会对您的基础环境产生不必要的影响。因此,当我们遇到包冲突时,创建环境将使您免于头痛。 conda 将为您管理依赖项。

【讨论】:

【参考方案4】:

你需要编译它。安装 Visual Studio 2019 和 CMake。

然后转到你的 dlib 文件夹,打开终端并使用命令

python3 setup.py sdist bdist_wheel

它将加载大量文本,然后您的 dist 文件夹中将有一个 wheel 文件。确保您的 Python 3.7.2 对应于 dlib version

最后,你只需要pip install cp37.whl

【讨论】:

【参考方案5】:

我尝试了很多方法来使用最新版本的 Anaconda,即 Python 3.7。但是,我无法这样做。因为没有一个 .whl 文件与 Python 3.7 兼容,而是与 Python 3.6 兼容。所以,我跟着the link 将 Python 版本降级到 3.6。这样 spyder 和 Python 将被降级到 3.6 版本。完成后,我使用以下命令安装了 OpenCV。

pip install opencv-python
pip install opencv-contrib-python

我使用以下命令安装了 dlib。

pip install dlib-19.8.1-cp36-cp36m-win_amd64.whl

这样就成功安装了最新版本的dlib。

为了检查一切是否安装正确,我使用的命令和我在 Anaconda 提示符下得到的输出如下。

(py36) C:\Users\dbi227> python
Python 3.6.9 |Anaconda, Inc.| (default, Jul 30 2019, 14:00:49) [MSC v.1915 64 bit (AMD64)] on win32
Type "help", "copyright", "credits" or "license" for more information.
>>> import cv2
>>> cv2.__version__
'4.1.1'
>>> import dlib
>>> dlib.__version__
'19.8.1'

检查您的 iPython 安装是否也降级到 3.6 很重要。为此,我在开始选项中除了 spyder(anaconda3) 之外还有一个选项 spyder(py36)。确保单击 spyder(py36)。因为那是安装库的地方。要检查它,您只需键入:

import cv2
import dlib

如果这些命令没有显示任何错误,则说明库已正确安装。

【讨论】:

以上是关于无法在 Windows 10 和 Python 3.7 上安装 dlib的主要内容,如果未能解决你的问题,请参考以下文章

无法识别使用 Ubuntu bash 在 Windows 10 上安装的 Python 模块

无法在 Windows 10 上的 python 3.6 64 位上运行 pyqt5(没有 anaconda 没有 virtualenv)

无法加载原生 TensorFlow 运行时。 Windows 10 上的 Python 3.6

Kivy 错误,[CRITICAL] [Text] 无法找到任何有价值的文本提供程序(python 3.6.1)(windows 10)

无法安装 Kivy(Windows 10,python 3.8)[重复]

无法在我的 Windows 10 上安装“Turicreate”