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

我正在尝试安装 dlib。我遵循了互联网上的每一个提示,但它只是不起作用。我正在使用/尝试

我已经安装了 conda 和 pip,都试过了

  • pip 安装 dlib
  • pip install dlib --verbose
  • pip install “一些网址”
  • conda install -c conda-forge dlib
  • conda install -c conda-forge/label/cf201901 dlib

我得到的错误是:

 Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:UserssophiAppDataLocalTemppip-install-3w7lgrlbdlib_ffabe5e6a08e472b835f598e7803e3d4setup.py", line 222, in <module>
        setup(
      File "c:userssophianaconda3libsite-packagessetuptools__init__.py", line 159, in setup
        return distutils.core.setup(**attrs)
      File "c:userssophianaconda3libdistutilscore.py", line 148, in setup
        dist.run_commands()
      File "c:userssophianaconda3libdistutilsdist.py", line 966, in run_commands
        self.run_command(cmd)
      File "c:userssophianaconda3libdistutilsdist.py", line 985, in run_command
        cmd_obj.run()
      File "c:userssophianaconda3libsite-packagessetuptoolscommandinstall.py", line 68, in run
        return orig.install.run(self)
      File "c:userssophianaconda3libdistutilscommandinstall.py", line 545, in run
        self.run_command('build')
      File "c:userssophianaconda3libdistutilscmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:userssophianaconda3libdistutilsdist.py", line 985, in run_command
        cmd_obj.run()
      File "c:userssophianaconda3libdistutilscommandbuild.py", line 135, in run
        self.run_command(cmd_name)
      File "c:userssophianaconda3libdistutilscmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:userssophianaconda3libdistutilsdist.py", line 985, in run_command
        cmd_obj.run()
      File "C:UserssophiAppDataLocalTemppip-install-3w7lgrlbdlib_ffabe5e6a08e472b835f598e7803e3d4setup.py", line 134, in run
        self.build_extension(ext)
      File "C:UserssophiAppDataLocalTemppip-install-3w7lgrlbdlib_ffabe5e6a08e472b835f598e7803e3d4setup.py", line 174, in build_extension
        subprocess.check_call(cmake_build, cwd=build_folder)
      File "c:userssophianaconda3libsubprocess.py", line 364, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--config', 'Release', '--', '/m']' returned non-zero exit status 1.
    Running setup.py install for dlib ... error
ERROR: Command errored out with exit status 1: 'c:userssophianaconda3python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:UserssophiAppDataLocalTemppip-install-3w7lgrlbdlib_ffabe5e6a08e472b835f598e7803e3d4setup.py'"'"'; __file__='"'"'C:UserssophiAppDataLocalTemppip-install-3w7lgrlbdlib_ffabe5e6a08e472b835f598e7803e3d4setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:UserssophiAppDataLocalTemppip-record-kvd3vwdqinstall-record.txt' --single-version-externally-managed --compile --install-headers 'c:userssophianaconda3Includedlib' Check the logs for full command output.

对我来说,问题似乎出在 cmake 命令上,但我不知道确切的问题是什么。我使用了 pip install cmake 并从源代码安装了 cmake,两者都没有工作。有谁知道如何解决这个问题?

stack overflow Error with Dlib installation for python on windows 10
原文答案

答案:

作者头像

这可能是迟到的反应,但我在尝试在 Visual Studio 代码上安装 dlib 时遇到了完全相同的问题。这是我在尝试运行命令“pip install dlib”时收到的错误

Collecting dlib
Using cached dlib-19.23.1.tar.gz (7.4 MB)
Preparing metadata (setup.py) ... done
Using legacy 'setup.py install' for dlib, since package 'wheel' is not installed.
Installing collected packages: dlib
  Running setup.py install for dlib ... error
  error: subprocess-exited-with-error

  × Running setup.py install for dlib did not run successfully.
  │ exit code: 1
  ╰─> [8 lines of output]
      running install
      running build
      running build_py
      package init file 'toolspythondlib__init__.py' not found (or not a regular file)
      running build_ext

      ERROR: CMake must be installed to build dlib

      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> dlib

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

因此,我的下一个方法是安装 cmake,它可以在安装工作的地方安装,但是我收到一条警告,即 exe 的文件路径未添加到我的路径中。这导致运行“cmake --version”以在终端中输出

'cmake' is not recognized as an internal or external command,
operable program or batch file.

我怀疑运行不正确,为了解决这个问题,我只需在安装 cmake 后将它打印出来的路径复制到我的终端并转到 Advance System Settings -> Advanced Tab -> 环境变量 -> “您的桌面名称”的用户变量打开“路径” -> 单击新的 -> 粘贴路径

按照这些步骤运行命令“cmake --version”后,正确打印出版本安装,这意味着它正在访问正确的路径。在那之后“pip install dlib”完美地工作如下证明

Collecting dlib
  Using cached dlib-19.23.1.tar.gz (7.4 MB)
  Preparing metadata (setup.py) ... done
Using legacy 'setup.py install' for dlib, since package 'wheel' is not installed.
Installing collected packages: dlib
  Running setup.py install for dlib ... done
Successfully installed dlib-19.23.1

我希望这可能会有所帮助,因为它是我安装 dlib 的一种方法。正如您提到的,您的 cmake 在路径上,我将通过运行命令来检查版本是否正确打印出来。

作者头像

Althoug 试图测试我的问题中提到的命令的每个组合,显然有一个组合我没有尝试过:Conda environment with python 3.6.4 然后

  • conda install -c conda-forge dlib

    Not able to install dlib on Windows 10 and Python 3.7 正如 Berkay 所说,anaconda 显然需要 python <=3.6.x,它为我解决了这个问题。 ! pip install dlib 在这种环境下不起作用(可能是因为这个环境的另一个版本问题)!