在Python中安装dlib



我想为一个即将启动的项目安装face_recognition。但是,face_recognition依赖于dlib,我不知道如何安装。

我进入pip install dlib,然而,一个错误被抛出,因为它说我需要安装CMake。下面是错误:

Using cached dlib-19.24.0.tar.gz (3.2 MB)
Preparing metadata (setup.py) ... done
Installing collected packages: dlib
DEPRECATION: dlib is being installed using the legacy 'setup.py install' method, because it does not have a 'pyproject.toml' and the 'wheel' package is not installed. pip 23.1 will enforce this behaviour change. A possible replacement is to enable the '--use-pep517' option. Discussion can be found at https://github.com/pypa/pip/issues/8559
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
╰─> [9 lines of output]
running install
C:Program FilesWindowsAppsPythonSoftwareFoundation.Python.3.10_3.10.2544.0_x64__qbz5n2kfra8p0libsite-packagessetuptoolscommandinstall.py:34: SetuptoolsDeprecationWarning: setup.py install is deprecated. Use build and pip and other standards-based tools.
warnings.warn(
running build
running build_py
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:
Collecting CMake
Using cached cmake-3.25.0-py2.py3-none-win_amd64.whl (32.6 MB)
Installing collected packages: CMake
WARNING: The scripts cmake.exe, cpack.exe and ctest.exe are installed in 'C:UsersEmmaAppDataLocalPackagesPythonSoftwareFoundation.Python.3.10_qbz5n2kfra8p0LocalCachelocal-packagesPython310Scripts' which is not on PATH.
Consider adding this directory to PATH or, if you prefer to suppress this warning, use --no-warn-script-location.
Successfully installed CMake-3.25.0

然而,当我试图再次安装dlib时,即使我成功安装了CMake,我也得到了同样的错误。

我现在如何安装dlib ?作为参考,我使用的是Windows 10或11系统,Python 3.11 64位。

更新/安装Visual c++

也许尝试安装/更新Visual c++。因为这是CMake运行所必需的。你可以从这里安装,https://visualstudio.microsoft.com/thank-you-downloading-visual-studio/?sku=Community&rel=15#

车轮文件安装

运行:

pip install https://pypi.python.org/packages/da/06/bd3e241c4eb0a662914b3b4875fc52dd176a9db0d4a2c915ac2ad8800e9e/dlib-19.7.0-cp36-cp36m-win_amd64.whl#md5=b7330a5b2d46420343fbed5df69e6a3f

从Internet安装

  1. Install CMake from https://cmake.org/download/
  2. 运行这个,set PATH="%PATH%;C:Program FilesCMakebin添加CMake到你的路径。您也可以通过编辑环境变量手动执行此操作。3)下载以下文件:https://pypi.org/project/dlib/文件。
  3. 在解压安装文件的指定文件夹中运行以下命令:python setup.py install