Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

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

pip3 install dlib

I have installed CMake, so that is not the problem.
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.

like image 335
owcs Avatar asked Feb 16 '19 03:02

owcs


People also ask

How do I install DLIB in Pycharm terminal?

Click the Python Interpreter tab within your project tab. Click the small + symbol to add a new library to the project. Now type in the library to be installed, in your example "dlib" without quotes, and click Install Package . Wait for the installation to terminate and close all popup windows.


3 Answers

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

    • See the "Install Homebrew" section of https://brew.sh/
    • Basically:
      $ /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install.sh)"
      
  2. Install Python3 (and pip3) using Homebrew

    • See https://docs.brew.sh/Homebrew-and-Python
    • See Homebrew's formula for the latest Python3 (python3.7, python3.8, python3.9)
    • Basically do one of the following:
      $ brew install [email protected]  # or [email protected] or [email protected]
      $ brew install python@3    # get whichever is the latest version
      
  3. Check Python installation

    $ python3 -V
    $ python3 -m pip -V
    
  4. Install CMake using Homebrew

    • See https://formulae.brew.sh/formula/cmake
    • Basically:
      $ brew install cmake
      
  5. Check CMake installation

    $ brew info cmake
    $ cmake --version
    
  6. Finally, install dlib with pip

    $ 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/.

like image 122
Gino Mempin Avatar answered Oct 05 '22 23:10

Gino Mempin


  1. Install Homebrew from here

  2. A bunch of dependencies are needed for 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
    
like image 41
Saisha Avatar answered Oct 06 '22 00:10

Saisha


dlib is dependent on cmake so you need to install that first. You just need to run following commands on your terminal:

$ brew install cmake 
$ pip install cmake 
$ brew install dlib 
$ pip install dlib
like image 45
Gourav Singh Bais Avatar answered Oct 05 '22 23:10

Gourav Singh Bais