如何在 mac 上为 python 安装 dlib?

owc*_*wcs 6 python macos pip dlib

尝试在 macOS 上的 Python 3.7 上安装 dlib 时出现错误

pip3 install dlib
Run Code Online (Sandbox Code Playgroud)

我已经安装了 CMake,所以这不是问题。
我收到这些错误消息:

Failed building wheel for dlib
Run Code Online (Sandbox Code Playgroud)

Command "/Library/Frameworks/Python.framework/Versions/3.7/bin/python3.7 -u -c "import setuptools, tokenize;__file__='/private/var/folders/j2/nvk5521j2vn9s1w95_0vlwkm0000gn/T/pip-install-ls2e_3mr/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 /private/var/folders/j2/nvk5521j2vn9s1w95_0vlwkm0000gn/T/pip-record-hy3hu262/install-record.txt --single-version-externally-managed --compile" 
failed with error code 1 in /private/var/folders/j2/nvk5521j2vn9s1w95_0vlwkm0000gn/T/pip-install-ls2e_3mr/dlib/ 
Run Code Online (Sandbox Code Playgroud)

最后是红色。我需要 dlib 的原因是安装 face_recognition。

Gin*_*pin 10

我认为错误消息还有更多,它可能与 CMake 有关,要么没有正确安装,要么与 pip3 install dlib.

我建议使用Homebrew安装 Python3(包括 pip3)和 CMake。Homebrew 管理可能依赖于系统相关工具、路径等的包、工具、库的安装。它还可以防止您不得不sudo在系统上安装东西。

  1. 安装 Homebrew

  2. 使用 Homebrew 安装 Python3(和 pip3)

  3. 检查 Python 安装

    $ brew install python@3.7  # or python@3.8 or python@3.9
    $ brew install python@3    # get whichever is the latest version
    
    Run Code Online (Sandbox Code Playgroud)
  4. 使用 Homebrew 安装 CMake

  5. 检查 CMake 安装

    $ brew info cmake
    $ cmake --version
    
    Run Code Online (Sandbox Code Playgroud)
  6. 最后,安装 dlib pip

    $ python3 -V
    $ python3 -m pip -V
    
    Run Code Online (Sandbox Code Playgroud)

如果您不想使用 Homebrew(出于某种原因),您可以尝试使用以下安装程序(dmg 或 tar.gz)直接安装 CMake for Mac:https : //cmake.org/download/