Search code examples
pythonpython-3.xcmakedlib

Error installing dlib in python on ubuntu


I want to use OpenCV for a python project and for that reason want to install dlib library. I ran the command pip install dliband it gave me following error:

  Installing build dependencies ... done
  Getting requirements to build wheel ... done
  Preparing metadata (pyproject.toml) ... done
Building wheels for collected packages: dlib
  Building wheel for dlib (pyproject.toml) ... error
  error: subprocess-exited-with-error
  
  × Building wheel for dlib (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [6 lines of output]
      running bdist_wheel
      running build
      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: Failed building wheel for dlib
Failed to build dlib
ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects

Since the error was Cmake must be installed I installed Cmake using pip install cmake but the errror still persisted. So I also installed cmake as mentioned here but the error still persist.


Solution

  • Since you are using anacoda you probably have messed up your run environment. Your error doesn't provide insight on what actually has happened but a makeshift, however it is demotivated, can fix your error.

    After installing cmake as mentioned in link answered install packages in root directory using sudo pip install cmake and sudo pip install dlib.

    Then you can import the modules in root directory using sys module as follows:

    import sys
    
    sys.path.insert(0, '/usr/path/to/modules/dlib')