Skip to content

Instantly share code, notes, and snippets.

@ageitgey
Last active April 30, 2024 08:21
Show Gist options
  • Save ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf to your computer and use it in GitHub Desktop.
Save ageitgey/629d75c1baac34dfa5ca2a1928a7aeaf to your computer and use it in GitHub Desktop.

How to install dlib v19.9 or newer (w/ python bindings) from github on macOS and Ubuntu

Pre-reqs:

  • Have Python 3 installed. On macOS, this could be installed from homebrew or even via standard Python 3.6 downloaded installer from https://www.python.org/download. On Linux, just use your package manager.
  • On macOS:
    • Install XCode from the Mac App Store (or install the XCode command line utils).
    • Have homebrew installed
  • On Linux:
    • For a full list of apt packages required, check out the example Dockerfile and copy what's installed there.
    • These instructions assume you are using Ubuntu 16.04 or newer. If you are using 14.04, you can try these installation instructions instead to work around the old CMake version.
  • These instructions assume you don't have an nVidia GPU and don't have Cuda and cuDNN installed and don't want GPU acceleration (since none of the current Mac models support this).

Clone the code from github:

git clone https://github.com/davisking/dlib.git

Build the main dlib library (optional if you just want to use Python):

cd dlib
mkdir build; cd build; cmake ..; cmake --build .

Build and install the Python extensions:

cd ..
python3 setup.py install

At this point, you should be able to run python3 and type import dlib successfully.

@Cyb3r-0
Copy link

Cyb3r-0 commented Dec 24, 2023

dlib installing issue using Command prompt and vs code both in window 11 can you please guide

PS C:\Users\TARUN PAUL\Coding> pip install cmake
Collecting cmake
Using cached cmake-3.28.1-py2.py3-none-win_amd64.whl.metadata (6.5 kB)
Using cached cmake-3.28.1-py2.py3-none-win_amd64.whl (35.8 MB)
Installing collected packages: cmake
Successfully installed cmake-3.28.1
PS C:\Users\TARUN PAUL\Coding> pip install dlib
Collecting dlib
Using cached dlib-19.24.2.tar.gz (11.8 MB)
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
╰─> [78 lines of output]
running bdist_wheel
running build
running build_ext
:125: DeprecationWarning: distutils Version classes are deprecated. Use packaging.version instead.
Building extension for Python 3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)]
Invoking CMake setup: 'cmake C:\Users\TARUN PAUL\AppData\Local\Temp\pip-install-ao8p44qq\dlib_871dc5b39a78423394254e859b7bb660\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\TARUN PAUL\AppData\Local\Temp\pip-install-ao8p44qq\dlib_871dc5b39a78423394254e859b7bb660\build\lib.win-amd64-cpython-311 -DPYTHON_EXECUTABLE=C:\Users\TARUN PAUL\AppData\Local\Programs\Python\Python311\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\TARUN PAUL\AppData\Local\Temp\pip-install-ao8p44qq\dlib_871dc5b39a78423394254e859b7bb660\build\lib.win-amd64-cpython-311 -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 "C:\Users\TARUN PAUL\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 353, in <module>
      main()
    File "C:\Users\TARUN PAUL\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 335, in main
      json_out['return_val'] = hook(**hook_input['kwargs'])       
                               ^^^^^^^^^^^^^^^^^^^^^^^^^^^^       
    File "C:\Users\TARUN PAUL\AppData\Local\Programs\Python\Python311\Lib\site-packages\pip\_vendor\pyproject_hooks\_in_process\_in_process.py", line 251, in build_wheel
      return _build_backend().build_wheel(wheel_directory, config_settings,
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\build_meta.py", line 404, in build_wheel
      return self._build_with_temp_dir(
             ^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\build_meta.py", line 389, in _build_with_temp_dir
      self.run_setup()
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\build_meta.py", line 311, in run_setup
      exec(code, locals())
    File "<string>", line 218, in <module>
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\__init__.py", line 103, in setup
      return distutils.core.setup(**attrs)
             ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
      return run_commands(dist)
             ^^^^^^^^^^^^^^^^^^
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
      dist.run_commands()
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands
      self.run_command(cmd)
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\dist.py", line 963, in run_command
      super().run_command(command)
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
      cmd_obj.run()
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\wheel\bdist_wheel.py", line 368, in run
      self.run_command("build")
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
      self.distribution.run_command(command)
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\dist.py", line 963, in run_command
      super().run_command(command)
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
      cmd_obj.run()
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\_distutils\command\build.py", line 131, in run
      self.run_command(cmd_name)
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
      self.distribution.run_command(command)
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\dist.py", line 963, in run_command
      super().run_command(command)
    File "C:\Users\TARUN PAUL\AppData\Local\Temp\pip-build-env-2a2d9owp\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
      cmd_obj.run()
    File "<string>", line 130, in run
    File "<string>", line 167, in build_extension
    File "C:\Users\TARUN PAUL\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 413, in check_call
      raise CalledProcessError(retcode, cmd)
  subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\TARUN PAUL\\AppData\\Local\\Temp\\pip-install-ao8p44qq\\dlib_871dc5b39a78423394254e859b7bb660\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\TARUN PAUL\\AppData\\Local\\Temp\\pip-install-ao8p44qq\\dlib_871dc5b39a78423394254e859b7bb660\\build\\lib.win-amd64-cpython-311', '-DPYTHON_EXECUTABLE=C:\\Users\\TARUN PAUL\\AppData\\Local\\Programs\\Python\\Python311\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\TARUN PAUL\\AppData\\Local\\Temp\\pip-install-ao8p44qq\\dlib_871dc5b39a78423394254e859b7bb660\\build\\lib.win-amd64-cpython-311', '-A', 'x64']' returned non-zero exit status 1.
  [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

@liwg1995
Copy link

liwg1995 commented Dec 24, 2023 via email

@Cyb3r-0
Copy link

Cyb3r-0 commented Dec 25, 2023

好的。
一旦您得到我的问题相关模块的答案,请尽快回复我。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment