"ERROR: Could not build wheels for dlib, which is required to install pyproject.toml-based projects" while installing dlib in PowerShell
Asked Answered
S

3

6

I have been building a facial recognition tool and I am trying to install dlib.

Every time I have tried to install dlib, I get this message:

  × 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
      <string>: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\Jack\AppData\Local\Temp\pip-install-tl9fdcf0\dlib_fee2183dfbb9404395bfedaca5728c1a\tools\python -DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\Users\Jack\AppData\Local\Temp\pip-install-tl9fdcf0\dlib_fee2183dfbb9404395bfedaca5728c1a\build\lib.win-amd64-cpython-311 -DPYTHON_EXECUTABLE=C:\Users\Jack\AppData\Local\Programs\Python\Python311\python.exe -DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\Users\Jack\AppData\Local\Temp\pip-install-tl9fdcf0\dlib_fee2183dfbb9404395bfedaca5728c1a\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\Jack\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\Jack\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\Jack\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\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\build_meta.py", line 416, in build_wheel
          return self._build_with_temp_dir(['bdist_wheel'], '.whl',
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\build_meta.py", line 401, in _build_with_temp_dir
          self.run_setup()
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\build_meta.py", line 338, in run_setup
          exec(code, locals())
        File "<string>", line 218, in <module>
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\__init__.py", line 107, in setup
          return distutils.core.setup(**attrs)
                 ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 185, in setup
          return run_commands(dist)
                 ^^^^^^^^^^^^^^^^^^
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\_distutils\core.py", line 201, in run_commands
          dist.run_commands()
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 969, in run_commands
          self.run_command(cmd)
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\dist.py", line 1234, in run_command
          super().run_command(command)
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
          cmd_obj.run()
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\wheel\bdist_wheel.py", line 343, in run
          self.run_command("build")
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\dist.py", line 1234, in run_command
          super().run_command(command)
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\_distutils\dist.py", line 988, in run_command
          cmd_obj.run()
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\_distutils\command\build.py", line 131, in run
          self.run_command(cmd_name)
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\_distutils\cmd.py", line 318, in run_command
          self.distribution.run_command(command)
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\overlay\Lib\site-packages\setuptools\dist.py", line 1234, in run_command
          super().run_command(command)
        File "C:\Users\Jack\AppData\Local\Temp\pip-build-env-ar6t1xkr\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\Jack\AppData\Local\Programs\Python\Python311\Lib\subprocess.py", line 413, in check_call
          raise CalledProcessError(retcode, cmd)
      subprocess.CalledProcessError: Command '['cmake', 'C:\\Users\\Jack\\AppData\\Local\\Temp\\pip-install-tl9fdcf0\\dlib_fee2183dfbb9404395bfedaca5728c1a\\tools\\python', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY=C:\\Users\\Jack\\AppData\\Local\\Temp\\pip-install-tl9fdcf0\\dlib_fee2183dfbb9404395bfedaca5728c1a\\build\\lib.win-amd64-cpython-311', '-DPYTHON_EXECUTABLE=C:\\Users\\Jack\\AppData\\Local\\Programs\\Python\\Python311\\python.exe', '-DCMAKE_LIBRARY_OUTPUT_DIRECTORY_RELEASE=C:\\Users\\Jack\\AppData\\Local\\Temp\\pip-install-tl9fdcf0\\dlib_fee2183dfbb9404395bfedaca5728c1a\\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

I have already installed CMake the correct way. Visual Studio is also installed. How do I fix this error?

Schaffel answered 6/7, 2023 at 13:51 Comment(2)
Please provide the complete error message, information about your python environemnt (version, other packages installed....) and your operating systemSlowly
Just did that hereSchaffel
B
17

It looks like you are using Python 3.11. Here's a solution which works for Python versions: 3.7, 3.8 and 3.9:

  1. Create a virtual environment via venv or Anaconda i.e. conda create -n your_env python = 3.8. I tested with Python 3.8 and it works.
  2. Download the wheel file from this repo for your specific Python version
  3. Open a terminal and install Dlib via:
python -m pip install dlib-19.22.99-cp38-cp38-win_amd64.whl 

This should help you to install dlib 19.22.99!

UPDATE (DEC 2023): For anyone who's having an issue with building wheels for the Dlib library, please use this repo which also contains the wheels for Python 3.10 and 3.11.

UPDATE (MAY 2024): The repo now includes wheel for Python 3.12.

NOTE: These wheel files can only be used to install Dlib on Windows x64 OS.

BUILD FROM SOURCE: If you'd like to build it from source, follow these exact steps as per their docs:

  1. Install Visual Studio 2022 with the option Desktop Development with C++
  2. Create a virtual env as suggested above
  3. Execute these commands:
git clone https://github.com/davisking/dlib.git
cd dlib
pip install build
python -m build --wheel # Upon successful run, a ".whl" binary will be created under "dlib/dist/" 
pip install dist/dlib-<version>.whl # replace <version> with the exact name of the ".whl" file
Brainchild answered 6/7, 2023 at 15:8 Comment(7)
Fine, the binaries work. But why is that we cannot install from source? It should be the easiest way.Perforated
It is but not as easy as doing only pip install dlib on PowerShell which seems like you did as I see from your discussion here. I updated my answer to include the steps to build from source. I hope you find it useful.Brainchild
The whole point of pip is to abstract away these things. If you publish something used by these many people, this troublesome to install... Something is simply wrong.Perforated
I honestly don't see how your complain regarding pip is related to the answer I suggested here. I am not the official maintainer of the dlib package on PyPi. I simply created a repo with the pre-compiled binaries for anyone who's facing issues with building the library. If you don't wanna use the wheels, don't use it. It's a lost cause to complain here about why you can't simply do a pip install dlib and quite irrational to blame a suggestion for no apparent reason.Brainchild
No, you misunderstood me. I'm not complaining about your solution. I'm just complaining about the guys who originally published this, apparently, faulty build.Perforated
That's true. I think it has been an ongoing issue for quite some time now. The problem (as I understand) is not with their build but with the cmake version that comes with pip as mentioned by the author. That's why many others are still facing issues to build the binaries on their own system.Brainchild
This answer work for me!!!Clapperclaw
T
2
pip install cmake==3.25.2
pip install dlib==19.24.2

enter image description here

I also encountered the same problem, My solution is to install the specified version mentioned above (the latest version cannot be installed)

Telling answered 6/7, 2023 at 13:52 Comment(1)
As it’s currently written, your answer is unclear. Please edit to add additional details that will help others understand how this addresses the question asked.Edelstein
L
0

Be sure that you have cmake installed globally on your system and NOT on your python env.

pip uninstall cmake
which cmake
# /usr/local/bin/cmake

MacOS

brew install cmake 
Licastro answered 4/9 at 5:20 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.