pythonpippycharmdlibpython-3.9

dlib not installing pycharm, how to fix? No other posts have helped. I need to use python 3.9


I am not able to install dlib on my computer. It gives me this error, but no other posts have helped me. I have been searching for a few hours now but to no avail. I am not familiar with the pip command, so this error does not tell me any meaningful information. Can someone who is more experienced please tell me why this is not working? I have already tried reinstalling Microsoft Visual Studio C++ 2015, but that did not work. Installing CMake did not work either. Can someone please help me fix this?

Error:

pip install dlib
Collecting dlib
  Using cached dlib-19.22.1.tar.gz (7.4 MB)
Building wheels for collected packages: dlib
  Building wheel for dlib (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: 'C:\Users\danie\Desktop\pythonProject\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\danie\\AppData
\\Local\\Temp\\pip-install-qaxhyxsu\\dlib_74869802ec0f4350b1acbcfa765926a5\\setup.py'"'"'; __file__='"'"'C:\\Users\\danie\\AppData\\Local\\Temp\\pip-install-qaxhyxsu\\d
lib_74869802ec0f4350b1acbcfa765926a5\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setupto
ols import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d 'C:\Users\
danie\AppData\Local\Temp\pip-wheel-aho58vt2'
       cwd: C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\
  Complete output (58 lines):
  running bdist_wheel
  running build
  running build_py
  package init file 'tools\python\dlib\__init__.py' not found (or not a regular file)
  running build_ext
  Building extension for Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]
  Invoking CMake setup: 'cmake C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTOR
Y=C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\build\lib.win-amd64-3.9 -DPYTHON_EXECUTABLE=C:\Users\danie\Desktop\python
Project\venv\Scripts\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\bu
ild\lib.win-amd64-3.9 -A x64'
  -- Building for: NMake Makefiles
  CMake Error at CMakeLists.txt:5 (message):
  
  
  
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  
  
    You must use Visual Studio to build a python extension on windows.  If you
    are getting this error it means you have not installed Visual C++.  Note
    that there are many flavors of Visual Studio, like Visual Studio for C#
    development.  You need to install Visual Studio for C++.
  
  
    !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
  
  
  
  
  -- Configuring incomplete, errors occurred!
  Traceback (most recent call last):
    File "<string>", line 1, in <module>
    File "C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\setup.py", line 222, in <module>
      setup(
    File "C:\Users\danie\Desktop\pythonProject\venv\lib\site-packages\setuptools\__init__.py", line 153, in setup
      return distutils.core.setup(**attrs)
    File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\core.py", line 148, in setup
      dist.run_commands()
    File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\dist.py", line 966, in run_commands
      self.run_command(cmd)
    File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\danie\Desktop\pythonProject\venv\lib\site-packages\wheel\bdist_wheel.py", line 299, in run
      self.run_command('build')
    File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\command\build.py", line 135, in run
      self.run_command(cmd_name)
    File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\cmd.py", line 313, in run_command
      self.distribution.run_command(command)
    File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\dist.py", line 985, in run_command
      cmd_obj.run()
    File "C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\setup.py", line 134, in run
      self.build_extension(ext)
    File "C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\setup.py", line 171, in build_extension
      subprocess.check_call(cmake_setup, cwd=build_folder)
    File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 373, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\danie\\AppData\\Local\\Temp\\pip-install-qaxhyxsu\\dlib_74869802ec0f4350b1acbcfa765926a5\\tools\\python'
, '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\danie\\AppData\\Local\\Temp\\pip-install-qaxhyxsu\\dlib_74869802ec0f4350b1acbcfa765926a5\\build\\lib.win-amd64-3.9', '-DP
YTHON_EXECUTABLE=C:\\Users\\danie\\Desktop\\pythonProject\\venv\\Scripts\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\danie\\AppData\\Local\\Temp\
\pip-install-qaxhyxsu\\dlib_74869802ec0f4350b1acbcfa765926a5\\build\\lib.win-amd64-3.9', '-A', 'x64']' returned non-zero exit status 1.
  ----------------------------------------
  ERROR: Failed building wheel for dlib
  Running setup.py clean for dlib
Failed to build dlib
Installing collected packages: dlib
    Running setup.py install for dlib ... error
    ERROR: Command errored out with exit status 1:
     command: 'C:\Users\danie\Desktop\pythonProject\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'C:\\Users\\danie\\AppDa
ta\\Local\\Temp\\pip-install-qaxhyxsu\\dlib_74869802ec0f4350b1acbcfa765926a5\\setup.py'"'"'; __file__='"'"'C:\\Users\\danie\\AppData\\Local\\Temp\\pip-install-qaxhyxsu\
\dlib_74869802ec0f4350b1acbcfa765926a5\\setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setup
tools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record 'C:\Us
ers\danie\AppData\Local\Temp\pip-record-3n7tervb\install-record.txt' --single-version-externally-managed --compile --install-headers 'C:\Users\danie\Desktop\pythonProje
ct\venv\include\site\python3.9\dlib'
         cwd: C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\
    Complete output (60 lines):
    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
    Building extension for Python 3.9.5 (tags/v3.9.5:0a7dcbd, May  3 2021, 17:27:52) [MSC v.1928 64 bit (AMD64)]
    Invoking CMake setup: 'cmake C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECT
ORY=C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\build\lib.win-amd64-3.9 -DPYTHON_EXECUTABLE=C:\Users\danie\Desktop\pyth
onProject\venv\Scripts\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\
build\lib.win-amd64-3.9 -A x64'
    -- Building for: NMake Makefiles
    CMake Error at CMakeLists.txt:5 (message):
    
    
    
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    
      You must use Visual Studio to build a python extension on windows.  If you
      are getting this error it means you have not installed Visual C++.  Note
      that there are many flavors of Visual Studio, like Visual Studio for C#
      development.  You need to install Visual Studio for C++.
    
    
      !!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!!
    
    
    
    
    -- Configuring incomplete, errors occurred!
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\setup.py", line 222, in <module>
        setup(
      File "C:\Users\danie\Desktop\pythonProject\venv\lib\site-packages\setuptools\__init__.py", line 153, in setup
        return distutils.core.setup(**attrs)
      File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\danie\Desktop\pythonProject\venv\lib\site-packages\setuptools\command\install.py", line 61, in run
        return orig.install.run(self)
      File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\command\install.py", line 546, in run
        self.run_command('build')
      File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\setup.py", line 134, in run
        self.build_extension(ext)
      File "C:\Users\danie\AppData\Local\Temp\pip-install-qaxhyxsu\dlib_74869802ec0f4350b1acbcfa765926a5\setup.py", line 171, in build_extension
        subprocess.check_call(cmake_setup, cwd=build_folder)
      File "C:\Users\danie\AppData\Local\Programs\Python\Python39\lib\subprocess.py", line 373, in check_call
        raise CalledProcessError(retcode, cmd)
    subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\danie\\AppData\\Local\\Temp\\pip-install-qaxhyxsu\\dlib_74869802ec0f4350b1acbcfa765926a5\\tools\\pytho
n', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\danie\\AppData\\Local\\Temp\\pip-install-qaxhyxsu\\dlib_74869802ec0f4350b1acbcfa765926a5\\build\\lib.win-amd64-3.9', '-
DPYTHON_EXECUTABLE=C:\\Users\\danie\\Desktop\\pythonProject\\venv\\Scripts\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\danie\\AppData\\Local\\Tem
p\\pip-install-qaxhyxsu\\dlib_74869802ec0f4350b1acbcfa765926a5\\build\\lib.win-amd64-3.9', '-A', 'x64']' returned non-zero exit status 1.
    ----------------------------------------
ERROR: Command errored out with exit status 1: 'C:\Users\danie\Desktop\pythonProject\venv\Scripts\python.exe' -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[
0] = '"'"'C:\\Users\\danie\\AppData\\Local\\Temp\\pip-install-qaxhyxsu\\dlib_74869802ec0f4350b1acbcfa765926a5\\setup.py'"'"'; __file__='"'"'C:\\Users\\danie\\AppData\\L
ocal\\Temp\\pip-install-qaxhyxsu\\dlib_74869802ec0f4350b1acbcfa765926a5\\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__, '"'"'exe
c'"'"'))' install --record 'C:\Users\danie\AppData\Local\Temp\pip-record-3n7tervb\install-record.txt' --single-version-externally-managed --compile --install-headers 'C
:\Users\danie\Desktop\pythonProject\venv\include\site\python3.9\dlib' Check the logs for full command output.
WARNING: You are using pip version 21.1.2; however, version 21.3.1 is available.
You should consider upgrading via the 'C:\Users\danie\Desktop\pythonProject\venv\Scripts\python.exe -m pip install --upgrade pip' command.

Solution

  • download cmake executable file on your pc, install it and install cmake build tools for c++ from visual studio build tools. After installing cmake with visual studio build tools, you need to download dlib wheel file from this github repo: https://github.com/Tobyyosoba777/Computer-Vision-OpenCv-Python-/tree/main/Libraries

    download: dlib-19.22.99-cp39-cp39-win_amd64.whl

    and download: dlib-19.22.99.win-amd64-py3.9.exe

    install the .exe file on your pc, restart it(not necessary) and open the current directory of the downloaded .whl file where it is saved on your pc in your python/anaconda terminal/ cmd

    for example:

    C:\Users\USER->cd desktop "if you downloaded the file to your desktop" this command will move you to the current directory of the .whl file

    then input: "pip install dlib-19.22.99-cp39-cp39-win_amd64.whl"

    that should work