简体   繁体   English

如何在mac上为python安装dlib?

[英]How to install dlib for python on mac?

I'm getting an error when trying to install dlib on Python 3.7 on macOS with尝试在 macOS 上的 Python 3.7 上安装 dlib 时出现错误

pip3 install dlib

I have installed CMake, so that is not the problem.我已经安装了 CMake,所以这不是问题。
I'm getting these error messages:我收到这些错误消息:

Failed building wheel for dlib

and

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/ 

at the end in red.最后是红色。 The reason I need dlib is to install face_recognition.我需要 dlib 的原因是安装 face_recognition。

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 .我认为错误消息还有更多,它可能与 CMake 相关,要么没有正确安装,要么与pip3 install dlib不兼容。

I suggest using Homebrew to install Python3 (which includes pip3) and CMake.我建议使用Homebrew安装 Python3(包括 pip3)和 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. Homebrew 管理可能依赖于系统相关工具、路径等的包、工具、库的安装。它还可以防止您必须使用sudo在您的系统上安装东西。

  1. Install Homebrew安装 Homebrew

    • See the " Install Homebrew " section of https://brew.sh/请参阅https://brew.sh/的“安装 Homebrew ”部分
    • Basically:基本上:
       $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
  2. Install Python3 (and pip3) using Homebrew使用 Homebrew 安装 Python3(和 pip3)

  3. Check Python installation检查 Python 安装

    $ python3 -V $ python3 -m pip -V
  4. Install CMake using Homebrew使用 Homebrew 安装 CMake

  5. Check CMake installation检查 CMake 安装

    $ brew info cmake $ cmake --version
  6. Finally, install dlib with pip最后,用pip安装dlib

     $ python3 -m pip 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/ .如果您不想使用 Homebrew(出于某种原因),您可以尝试使用以下安装程序(dmg 或 tar.gz)直接安装 CMake for Mac: https : //cmake.org/download/

  1. Install Homebrew from here这里安装 Homebrew

  2. A bunch of dependencies are needed for dlib: 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. If this does not work, try:如果这不起作用,请尝试:

     python3 -m pip install dlib

dlib is dependent on cmake so you need to install that first. dlib 依赖于 cmake,因此您需要先安装它。 You just need to run following commands on your terminal:您只需要在终端上运行以下命令:

$ brew install cmake 
$ pip install cmake 
$ brew install dlib 
$ pip install dlib
$ pip3 install --upgrade pip

$ pip3 install global

$ pip3 install cmake

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

You can install the conda-forge Dlib package by running您可以通过运行安装 conda-forge Dlib 包


conda install -c conda-forge dlib conda install -c conda-forge dlib

Conda-forge has made sure to resolve all the dependency conflicts, so I had no issues with the installation. Conda-forge 已确保解决所有依赖项冲突,因此我的安装没有问题。 They have pre-built binaries for Windows, Linux, and Mac OS, and Python 2.7 through 3.8.他们为 Windows、Linux 和 Mac OS 以及 Python 2.7 到 3.8 预先构建了二进制文件。 The current package (at the time of this writing) is based on Dlib v19.19.当前包(在撰写本文时)基于 Dlib v19.19。

The only thing you need to do, I guess, is run pip3 install dlib with sudo.我猜你唯一需要做的就是使用 sudo 运行 pip3 install dlib。

sudo pip3 install dlib须藤 pip3 安装 dlib

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM