在Mac上的python中安装dlib

时间:2019-02-16 03:03:58

标签: python macos pip dlib

尝试使用pip3 install dlib在macOS上的Python 3.7中安装dlib时出现错误。我已经安装了CMake,所以这不是问题。

我收到此错误消息:
Failed building wheel for dlibandCommand "/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/

以红色结尾。我需要dlib的原因是要安装face_recognition。

我对python的了解很少。如果需要,我可以提供更多信息。

7 个答案:

答案 0 :(得分:3)

  1. 通过here

    安装Homebrew
  2. dlib需要一堆依赖项:

    brew install cmake
    brew install boost
    brew install boost-python
    brew install dlib
    pip3 install numpy
    pip3 install scipy
    pip3 install scikit-image
    pip3 install dlib
    
  3. 如果这不起作用,请尝试:

    python3 -m pip install dlib
    

答案 1 :(得分:0)

在某些情况下,由于Mac使用默认的python 2.7(您不应尝试将其删除),因此在访问python 3.x时可能会出现访问问题。

尝试通过运行它

sudo -H python3 -m pip install dlib

答案 2 :(得分:0)

I think there's more to the error message and it's probably related to CMake, either it's not installed properly or it's not compatible with the pip3 install dlib.

I suggest using Homebrew to install Python3 (which includes pip3) and CMake. Homebrew manages the installation of packages, tools, libraries that might depend on system-related tools, paths, etc. It also prevents you from having to use sudo to install stuff on your system.

  1. Install Homebrew

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

  1. Install Python3 (and pip3) using Homebrew

brew install python

  1. Check Python installation with brew info python3, python3 -V, pip3 -V

  2. Install CMake using Homebrew

brew install cmake

  1. Check CMake installation with brew info cmake and cmake --version

  2. Finally, install dlib with pip3 install dlib


If you don't want to use Homebrew (for some reason), you can try installing CMake for Mac directly using the installers (dmg or tar.gz) from here: https://cmake.org/download/.

答案 3 :(得分:0)

您可以通过运行来安装conda-forge Dlib软件包


conda install -c conda-forge dlib

Conda-forge已确保解决所有依赖关系冲突,因此安装没有问题。他们为Windows,Linux和Mac OS以及Python 2.7到3.8预先构建了二进制文件。当前的软件包(在撰写本文时)基于Dlib v19.19。

答案 4 :(得分:0)

$ pip3 install --upgrade pip

$ pip3 install global

$ pip3 install cmake

$ pip3 install dlib
$ brew install dlib
$ sudo pip install dlib

答案 5 :(得分:0)

我想,您唯一需要做的就是使用sudo运行pip3 install dlib。

sudo pip3安装dlib

答案 6 :(得分:0)

dlib依赖于cmake,因此您需要先安装它。 您只需要在终端上运行以下命令:

$ brew install cmake 
$ pip install cmake 
$ brew install dlib 
$ pip install dlib