'Error with Dlib installation for python on windows 10

I'm trying to install dlib. I followed every single tip on the internet but its just not working. I'm using/tried

I have conda and pip installed, tried both with

  • pip install dlib
  • pip install dlib --verbose
  • pip install "some urls"
  • conda install -c conda-forge dlib
  • conda install -c conda-forge/label/cf201901 dlib

The error I'm getting is:

 Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\sophi\AppData\Local\Temp\pip-install-3w7lgrlb\dlib_ffabe5e6a08e472b835f598e7803e3d4\setup.py", line 222, in <module>
        setup(
      File "c:\users\sophi\anaconda3\lib\site-packages\setuptools\__init__.py", line 159, in setup
        return distutils.core.setup(**attrs)
      File "c:\users\sophi\anaconda3\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "c:\users\sophi\anaconda3\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "c:\users\sophi\anaconda3\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "c:\users\sophi\anaconda3\lib\site-packages\setuptools\command\install.py", line 68, in run
        return orig.install.run(self)
      File "c:\users\sophi\anaconda3\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "c:\users\sophi\anaconda3\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:\users\sophi\anaconda3\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "c:\users\sophi\anaconda3\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "c:\users\sophi\anaconda3\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "c:\users\sophi\anaconda3\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\sophi\AppData\Local\Temp\pip-install-3w7lgrlb\dlib_ffabe5e6a08e472b835f598e7803e3d4\setup.py", line 134, in run
        self.build_extension(ext)
      File "C:\Users\sophi\AppData\Local\Temp\pip-install-3w7lgrlb\dlib_ffabe5e6a08e472b835f598e7803e3d4\setup.py", line 174, in build_extension
        subprocess.check_call(cmake_build, cwd=build_folder)
      File "c:\users\sophi\anaconda3\lib\subprocess.py", line 364, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', '--build', '.', '--config', 'Release', '--', '/m']' returned non-zero exit status 1.
    Running setup.py install for dlib ... error
ERROR: Command errored out with exit status 1: 'c:\users\sophi\anaconda3\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\sophi\\AppData\\Local\\Temp\\pip-install-3w7lgrlb\\dlib_ffabe5e6a08e472b835f598e7803e3d4\\setup.py'"'"'; __file__='"'"'C:\\Users\\sophi\\AppData\\Local\\Temp\\pip-install-3w7lgrlb\\dlib_ffabe5e6a08e472b835f598e7803e3d4\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Users\sophi\AppData\Local\Temp\pip-record-kvd3vwdq\install-record.txt' --single-version-externally-managed --compile --install-headers 'c:\users\sophi\anaconda3\Include\dlib' Check the logs for full command output.

For me, it seems like the problem is somethin with the cmake command, but I have no idea what the exact problem is. I used pip install cmake and installed cmake from source, none of both worked. Has anyone an idea how to solve this?



Solution 1:[1]

Althoug trying to test every combination of the commands mentioned in my question, there apparently was one combination I didn't try: Conda environment with python 3.6.4 and then

  • conda install -c conda-forge dlib

Not able to install dlib on Windows 10 and Python 3.7 As Berkay is mentioning, anaconda apparently requires python <=3.6.x, which solved it for me. ! pip install dlib would not work in this environment (probably because of another version problem with this environment) !

Solution 2:[2]

This may be late response but I was facing the exact same issue when trying to install dlib on visual studio code. This was my error I was receiving when trying to run the command "pip install dlib"

Collecting dlib
Using cached dlib-19.23.1.tar.gz (7.4 MB)
Preparing metadata (setup.py) ... done
Using legacy 'setup.py install' for dlib, since package 'wheel' is not installed.
Installing collected packages: dlib
  Running setup.py install for dlib ... error
  error: subprocess-exited-with-error

  × Running setup.py install for dlib did not run successfully.
  ? exit code: 1
  ??> [8 lines of output]
      running install
      running build
      running build_py
      package init file 'tools\python\dlib\__init__.py' not found (or not a regular file)
      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: legacy-install-failure

× Encountered error while trying to install package.
??> dlib

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

So my next approach was to install cmake which where the installation worked however I receive a warning that the file path to the exe was not added to my path. This resulted when running "cmake --version" to outputted in terminal

'cmake' is not recognized as an internal or external command,
operable program or batch file.

I would suspected to not run correctly, and to fix this I simply copy the path that it had printed out to my terminal after install cmake and went to Advance System Settings -> Advanced Tab -> Environment Variables -> User Variables for 'your desktop name' open up "Path" -> click on new -> paste path

After following those steps running the command "cmake --version" correctly printed out the version install, meaning it is accessing the correct path. After that "pip install dlib" worked perfectly as proof below

Collecting dlib
  Using cached dlib-19.23.1.tar.gz (7.4 MB)
  Preparing metadata (setup.py) ... done
Using legacy 'setup.py install' for dlib, since package 'wheel' is not installed.
Installing collected packages: dlib
  Running setup.py install for dlib ... done
Successfully installed dlib-19.23.1

I hope this may help as it is one approach that worked for me in installing dlib. As you mention your cmake is on path I would check by running the command to see if the version is correctly printing out.

Sources

This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.

Source: Stack Overflow

Solution Source
Solution 1 sophie
Solution 2 Matija Benko