Error installing dlib on Pycharm

11,181
  1. Installed Pycharm
  2. Windows 10
  3. Python 3.8.3 (with pipenv, but should work with pip also)

ex: pipenv install (as virtual env)

since "pipenv install dlib" was giving installation errors after struggling for sometime, able to install the latest dlib library (dlib==19.20.0)

Below is the procedure which helped me to succeed in installing the latest dlib - we have to Manually compile the dlib for Python

  1. Install visual studio (I installed Microsoft Visual Studio Community 2019 Version 16.6.3)
  2. Make Sure to select Visual C++ Or C++ environment - complete the installation - Nothing else is needed (In Visual Studio 2019 go to the Individual Components tab, Visual C++ Tools for Cmake, and check the checkbox under the "Compilers, build tools and runtimes" section.)
  3. Goto - https://cmake.org/download/ and download the cmake for 64bit (cmake-3.18.0-rc4-win64-x64.msi is what i installed)
  4. When installing, make sure to add CMake to the system path (once installation is complete -> check that Environment variable to see this is present)
  5. Goto https://pypi.org/project/dlib/ -> Click on "Download Files"
  6. dlib-19.20.0.tar.gz (is what i had as latest) -> Download the same
  7. extract the file "dlib-19.20.0.tar.gz" till you see the files (dlib, dlib.egg-info, python_examples, tools, MANIFEST.in, PKG-INFO, README.md setup.cfg, setup.py)
  8. Copy all these files (select all (ctrl+a)and copy(ctrl+c)) -> Make sure to copy only these files and not its parent directory along
  9. Goto site-packages in python installation (C:\Users<name>\AppData\Local\Programs\Python\Python38\Lib\site-packages)
  10. Paste all the files copied in step 7,8
  11. open command prompt and goto -> C:\Users<name>\AppData\Local\Programs\Python\Python38\Lib\site-packages
  12. execute command -> python setup.py install

Thats all you should be done - it might take 5 - 10 mins to complete the process, you should see something like below in the end Installed c:\users<name>\appdata\local\programs\python\python38\lib\site-packages\dlib-19.20.0-py3.8-win-amd64.egg Processing dependencies for dlib==19.20.0 Finished processing dependencies for dlib==19.20.0

Share:
11,181

Related videos on Youtube

mama
Author by

mama

Updated on September 18, 2022

Comments

  • mama
    mama over 1 year

    I am trying to install dlib on Pycharm (which is similar to Anaconda) in order to use it for my Python and OpenCV face detection project.

    I have installed cMake and upgraded Python but there is still an error:

    Command

    pip install dlib
    

    Error

    FileNotFoundError: [WinError 2] The system cannot find the file specified
    

    Command output

    Collecting dlib
      Using cached https://files.pythonhosted.org/packages/05/57/e8a8caa3c89a27f80bc78da39c423e2553f482a3705adc619176a3a24b36/dlib-19.17.0.tar.gz
    Installing collected packages: dlib
    Running setup.py install for dlib: started
    Running setup.py install for dlib: finished with status 'error'
    Complete output from command C:\Users\mehrs\PycharmProjects\project2\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\mehrs\\AppData\\Local\\Temp\\pycharm-packaging\\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 C:\Users\mehrs\AppData\Local\Temp\pip-record-_nvwlk_i\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\mehrs\PycharmProjects\project2\venv\include\site\python3.7\dlib:
    running install
    running build
    running build_py
    package init file 'dlib\__init__.py' not found (or not a regular file)
    warning: build_py: byte-compiling is disabled, skipping.
    
    running build_ext
    Traceback (most recent call last):
      File "C:\Users\mehrs\AppData\Local\Temp\pycharm-packaging\dlib\setup.py", line 120, in get_cmake_version
        out = subprocess.check_output(['cmake', '--version'])
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 395, in check_output
        **kwargs).stdout
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 472, in run
        with Popen(*popenargs, **kwargs) as process:
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 775, in __init__
        restore_signals, start_new_session)
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\subprocess.py", line 1178, in _execute_child
        startupinfo)
    FileNotFoundError: [WinError 2] The system cannot find the file specified
    
    During handling of the above exception, another exception occurred:
    
    Traceback (most recent call last):
      File "<string>", line 1, in <module>
      File "C:\Users\mehrs\AppData\Local\Temp\pycharm-packaging\dlib\setup.py", line 261, in <module>
        'Topic :: Software Development',
      File "C:\Users\mehrs\PycharmProjects\project2\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\setuptools\__init__.py", line 129, in setup
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\core.py", line 148, in setup
        dist.run_commands()
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 966, in run_commands
        self.run_command(cmd)
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\mehrs\PycharmProjects\project2\venv\lib\site-packages\setuptools-39.1.0-py3.7.egg\setuptools\command\install.py", line 61, in run
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\command\install.py", line 545, in run
        self.run_command('build')
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\command\build.py", line 135, in run
        self.run_command(cmd_name)
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\cmd.py", line 313, in run_command
        self.distribution.run_command(command)
      File "C:\Users\mehrs\AppData\Local\Programs\Python\Python37-32\lib\distutils\dist.py", line 985, in run_command
        cmd_obj.run()
      File "C:\Users\mehrs\AppData\Local\Temp\pycharm-packaging\dlib\setup.py", line 129, in run
        cmake_version = self.get_cmake_version()
      File "C:\Users\mehrs\AppData\Local\Temp\pycharm-packaging\dlib\setup.py", line 125, in get_cmake_version
        "\n*******************************************************************\n")
    RuntimeError:
    *******************************************************************
     CMake must be installed to build the following extensions: dlib
    *******************************************************************
    
    
    ----------------------------------------
    
    Command "C:\Users\mehrs\PycharmProjects\project2\venv\Scripts\python.exe -u -c "import setuptools, tokenize;__file__='C:\\Users\\mehrs\\AppData\\Local\\Temp\\pycharm-packaging\\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 C:\Users\mehrs\AppData\Local\Temp\pip-record-_nvwlk_i\install-record.txt --single-version-externally-managed --compile --install-headers C:\Users\mehrs\PycharmProjects\project2\venv\include\site\python3.7\dlib" failed with error code 1 in C:\Users\mehrs\AppData\Local\Temp\pycharm-packaging\dlib\
    You are using pip version 10.0.1, however version 19.0.3 is available.
    You should consider upgrading via the 'python -m pip install --upgrade pip' command.
    
    • Anaksunaman
      Anaksunaman about 5 years
      It appears you likely haven't registered cmake.exe at the command line (i.e. in your User/System PATH/Path variable(s)).