Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

[Bug]: cmake not found during dlib installation using pip (even though cmake installed correctly) #2961

Open
atharva-p opened this issue Jun 2, 2024 · 29 comments

Comments

@atharva-p
Copy link

What Operating System(s) are you seeing this problem on?

Windows

dlib version

19.24.4

Python version

3.12.1

Compiler

gcc

Expected Behavior

using pip in a virtual environment, install cmake using pip install cmake. then install dlib using pip install dlib. dlib installs successfully

Current Behavior

i've already installed cmake through pip. when i try to install dlib through pip, it tries to find cmake to build the wheel, however it is not able to. cmake requirement is already satisfied. i am using a virtual envrinoment. cmake.exe is also present in venv/Scripts

Steps to Reproduce

install dlib

(venv) PS C:\myFiles\dev\Hair_Style_Recommendation> pip install dlib

pip throws the following error

Collecting dlib
  Using cached dlib-19.24.4.tar.gz (3.3 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
  ╰─> [14 lines of output]
      <string>:210: SyntaxWarning: invalid escape sequence '\('
      <string>:211: SyntaxWarning: invalid escape sequence '\('
      <string>:212: SyntaxWarning: invalid escape sequence '\('
      running bdist_wheel
      running build
      running build_ext
      Traceback (most recent call last):
        File "<frozen runpy>", line 198, in _run_module_as_main
        File "<frozen runpy>", line 88, in _run_code
        File "C:\myFiles\dev\Hair_Style_Recommendation\venv\Scripts\cmake.exe\__main__.py", line 4, in <module>
      ModuleNotFoundError: No module named 'cmake'

      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: Failed building wheel for dlib

so i then check if cmake is installed. it is already installed.

(venv) PS C:\myFiles\dev\Hair_Style_Recommendation> python -m pip install cmake
Requirement already satisfied: cmake in c:\myfiles\dev\hair_style_recommendation\venv\lib\site-packages (3.29.3)

cmake.exe is also present in venv/Scripts

(venv) PS C:\myFiles\dev\Hair_Style_Recommendation> Test-path "venv\Scripts\cmake.exe"
True

however, it still cannot find it and installation fails

Anything else?

i am using windows 11 23h2. python version 3.12.1. pip version 24.0. cmake version (from pip) 3.29.3

@rickmaz
Copy link

rickmaz commented Jun 2, 2024

After you installed cmake did you try to do the dilib build in a new window session like a new command prompt. You should close that window and open a new one ideally with Administrator access. Also, you need visual studio installed to compile dlib with cmake also. Is cmake in your path? If you enter cmake --version for example does it show you the build number?

@davisking
Copy link
Owner

davisking commented Jun 2, 2024 via email

@lefteryx
Copy link

lefteryx commented Jun 2, 2024

Hi, installing cmake from apt works, yes, but for whatever reason, dlib=19.24.2 can be installed using the pip cmake but not dlib=19.24.4.
I'm not sure what the particular reason for this is though.

@atharva-p
Copy link
Author

atharva-p commented Jun 3, 2024

@davisking checked if cmake is in path, and it is

PS C:\Users\athar> cmake --version
cmake version 3.28.1

CMake suite maintained and supported by Kitware (kitware.com/cmake).

also i can build dlib with cmake but then can i use it with virtual environment that way? when i researched i got answers saying that i can't.

@atharva-p
Copy link
Author

@lefteryx i tried it out, and dlib 19.24.2 installs with pip cmake, however dlib 19.24.4 (latest) does not work

@davisking
Copy link
Owner

I'm not able to reproduce this. For me pip install dlib installs 19.24.4 without any issue. I'm guessing something is broken about your cmake install. You will have to debug it 🤷

Note that that error is saying cmake isn't in your PATH. You have to install cmake on your computer such that cmake is in your PATH so that programs can run cmake and not get an error about cmake not being available.

@lefteryx
Copy link

lefteryx commented Jun 8, 2024

Just to confirm and make sure we're on the same page, I meant that I can install dlib=19.24.2 using the pip cmake only without having the apt cmake or Visual Studio. Instaling dlib=19.24.4 does not work with ONLY pip install cmake and instead requires apt cmake.
Thanks for your response btw!

@davisking
Copy link
Owner

@lefteryx that's probably due to #2878

@lefteryx
Copy link

lefteryx commented Jun 9, 2024

Oh that is probably it, thank you very much for your response!

@dishuostec
Copy link

Just to confirm and make sure we're on the same page, I meant that I can install dlib=19.24.2 using the pip cmake only without having the apt cmake or Visual Studio. Instaling dlib=19.24.4 does not work with ONLY pip install cmake and instead requires apt cmake. Thanks for your response btw!

Confirmed.
I run pip install cmake then pip install dlib, and i got same error above. After pip uninstall cmake and sudo apt install cmake, I can install dlib without any error.

@dhruv-yadav-nitj
Copy link

What worked for me: [Windows]

  1. python v 3.8 ( i tried with 3.12, but did not worked)
  2. ensure that you have installed cmake in your venv before installing dlib
  3. download dlib-19.22.99-cp38-cp38-win_amd64.whl
  4. copy and paste the file 'dlib-19.22.99-cp38-cp38-win_amd64.whl' file in your project/venv/Scripts folder
  5. open project/venv/Scripts folder in terminal and pip install dlib-19.22.99-cp38-cp38-win_amd64.whl

if still this did not work then install Visual C++ from microsoft website, restart pc and try again!

@prathap1425
Copy link

Hi, installing cmake from apt works, yes, but for whatever reason, dlib=19.24.2 can be installed using the pip cmake but not dlib=19.24.4. I'm not sure what the particular reason for this is though.

same i cant find the reason why i cant able to install this dlib=19.12.4.

@313177606
Copy link

Same problem. wt do ?

@davisking
Copy link
Owner

If you open a terminal window and type cmake and hit enter what happens? I'm talking about the same terminal window you would use to install dlib. If when you type cmake in that window you get an error about cmake not being found then it's not installed correctly. So you have to install cmake such that opening a terminal window and typing cmake and hitting enter doesn't give an error. On windows the simplest way to do that is to use the installer from cmake.org.

To say that real clearly, in whatever window you use to type the install command for dlib. First just type cmake and hit enter. If you get an error stop and do not attempt to install dlib. First get cmake installed.

@Boetty
Copy link

Boetty commented Jul 15, 2024

sudo apt install git
activate your virtual environment...
Then:

pip install cmake

Check: cmake:

which cmake

Export path

export CMAKE=$(which cmake)

cmake --version

git clone https://github.com/davisking/dlib.git
cd dlib
mkdir build
cd build
cmake ..
cmake –build .

cd .. (you should now be back in the dlib dir)

python3 setup.py install

(lto-wrapper at the end takes time)

Check dlib installation:

python3 -c "import dlib; print(dlib.__version__)

@lucasjinreal
Copy link

Install from git is not the best way. I hit same error on CentOS, sadly I can not resolved it by using apt something, yum install cmake just doesn't work, even tough my cmake (pip) and yum already install.

Still throw error.

pip install dlib (latest):

CMake suite maintained and supported by Kitware (kitware.com/cmake).
Python 3.9.2 (default, Mar  3 2021, 20:02:32) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cmake
>>> from cmake import cmake
>>> 
  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
  ╰─> [10 lines of output]
      running bdist_wheel
      running build
      running build_ext
      Traceback (most recent call last):
        File "/data/miniconda3/envs/env-3.9.2/bin/cmake", line 5, in <module>
          from cmake import cmake
      ModuleNotFoundError: No module named 'cmake'
      
      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: Failed building wheel for dlib
Failed to build dlib

pip install dlib==19.24.2

Successfully built dlib
Installing collected packages: dlib
Successfully installed dlib-19.24.2

@davisking Can u just take a look at the build script difference between them? So many users claimed that it must have some miss looked imports in build script, please take a look, they shouldn't have behaviored so weired among all users.

Thanks for the lib!

@mayrinkdotcom
Copy link

mayrinkdotcom commented Aug 6, 2024

same problem here, trying to install CMake and then dlib in a Python venv v3.12 and got the error message:

error: subprocess-exited-with-error

  × Building wheel for dlib (pyproject.toml) did not run successfully.
  │ exit code: 1
  ╰─> [14 lines of output]
      <string>:196: SyntaxWarning: invalid escape sequence '\('
      <string>:197: SyntaxWarning: invalid escape sequence '\('
      <string>:198: SyntaxWarning: invalid escape sequence '\('
      running bdist_wheel
      running build
      running build_ext
      Traceback (most recent call last):
        File "<frozen runpy>", line 198, in _run_module_as_main
        File "<frozen runpy>", line 88, in _run_code
        File "C:\dev\facial_recognition\.venv\Scripts\cmake.exe\__main__.py", line 4, in <module>
      ModuleNotFoundError: No module named 'cmake'

      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: Failed building wheel for dlib
Failed to build dlib
ERROR: ERROR: Failed to build installable wheels for some pyproject.toml based projects (dlib)

@Boetty
Copy link

Boetty commented Aug 6, 2024

1.	Basics and Create faceuser without a password:

sudo apt update && sudo apt upgrade -y

sudo apt install -y python3 python3-pip python3-venv cmake git build-essential

sudo adduser --disabled-password --gecos "" faceuser

2.	Create the directory for the virtual environment:

sudo mkdir -p /home/faceuser/faceapp

sudo chown faceuser:faceuser /home/faceuser/faceapp

3.	Switch to the new user faceuser:

sudo -i -u faceuser

4.	Navigate to the directory for the virtual environment:

cd /home/faceuser/faceapp

5.	Set up the virtual environment:

python3 -m venv facevenv

6.	Activate the virtual environment:

source facevenv/bin/activate

7.	Install cmake:

pip install cmake

8.	Verify cmake installation:

which cmake

9.	Export the path to cmake:

export CMAKE=$(which cmake)

10.	Check cmake version:

cmake --version

11.	Clone dlib from GitHub:

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

12.	Change to the dlib directory:

cd dlib

13.	Create and switch to the build directory:

mkdir build
cd build

14.	Run cmake in the build directory:

cmake ..

15.	Build with cmake:

cmake --build .

16.	Switch back to the dlib directory:

cd ..

17.	Run setup.py to install dlib:

python3 setup.py install

18.	Verify dlib installation:

python3 -c "import dlib; print(dlib.version)"

19.	Install face_recognition:

cd..

pip install face_recognition

20.	Verify face_recognition installation:

python3 -c "import face_recognition; print(face_recognition.version)"

@davisking
Copy link
Owner

Install from git is not the best way. I hit same error on CentOS, sadly I can not resolved it by using apt something, yum install cmake just doesn't work, even tough my cmake (pip) and yum already install.

Still throw error.

pip install dlib (latest):

CMake suite maintained and supported by Kitware (kitware.com/cmake).
Python 3.9.2 (default, Mar  3 2021, 20:02:32) 
[GCC 7.3.0] :: Anaconda, Inc. on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import cmake
>>> from cmake import cmake
>>> 
  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
  ╰─> [10 lines of output]
      running bdist_wheel
      running build
      running build_ext
      Traceback (most recent call last):
        File "/data/miniconda3/envs/env-3.9.2/bin/cmake", line 5, in <module>
          from cmake import cmake
      ModuleNotFoundError: No module named 'cmake'
      
      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: Failed building wheel for dlib
Failed to build dlib

pip install dlib==19.24.2

Successfully built dlib
Installing collected packages: dlib
Successfully installed dlib-19.24.2

@davisking Can u just take a look at the build script difference between them? So many users claimed that it must have some miss looked imports in build script, please take a look, they shouldn't have behaviored so weired among all users.

Thanks for the lib!

@lucasjinreal, what exactly did you type to get these errors? The dlib setup.py file does not import cmake or have any dependency on any python cmake library. So I'm confused about where the errors you posted would be coming from

@davisking
Copy link
Owner

@mayrinkdotcom go to cmake.org, download their installer, and install it on your system. In the installer make sure you add cmake to your PATH when it asks if you want to do that.

@davisking
Copy link
Owner

@Boetty I'm not sure what your post is saying, but anyone using just python does not need to ever run any cmake build commands. Doing stuff like cmake .. and cmake --build . has no effect at all on any python user of dlib. So that is not needed.

@lucasjinreal
Copy link

@davisking Hello. Here is the issue. I merely executed pip install dlib and no other operations. I am unsure why the setup.py fails to import cmake but instead gets an import despite its installation. Currently, the old version functions. And I have abandoned face_recognition and utilized insightface instead. However, dlib is always an excellent library and I appreciate your work. I merely wish to assist to prevent anyone else from encountering the same error repeatedly. It is worthy of a thorough examination.

@davisking
Copy link
Owner

davisking commented Aug 9, 2024

@davisking Hello. Here is the issue. I merely executed pip install dlib and no other operations. I am unsure why the setup.py fails to import cmake but instead gets an import despite its installation. Currently, the old version functions. And I have abandoned face_recognition and utilized insightface instead. However, dlib is always an excellent library and I appreciate your work. I merely wish to assist to prevent anyone else from encountering the same error repeatedly. It is worthy of a thorough examination.

I'm not able to reproduce this. Frankly, what it looks like is /data/miniconda3/envs/env-3.9.2/bin/cmake is a python script that is broken. And /data/miniconda3/envs/env-3.9.2/bin is in your PATH. So when setup.py tries to run cmake it ends up running the broken /data/miniconda3/envs/env-3.9.2/bin/cmake script. That is, it's running a broken miniconda cmake python script rather than the official cmake binary.

What needs to happen is we somehow forbid use of any pip installed cmake. For years and years now various python package systems have offered to install cmake but many of them include broken copies of cmake. Like the /data/miniconda3/envs/env-3.9.2/bin/cmake there you see. I don't know what I can do on my end to prevent this from happening, since I don't have control over the miniconda cmake package.

But what you need to do is figure out how to get the real cmake in your PATH, then this will all work fine. Like if you do which cmake if it says you are using a miniconda cmake then that's bad. You want to use an official cmake package (official as in blessed by the people at cmake.org, not one from any python repacker as so many of them are broken as you see here). The cmake from yum should be fine on CentOS.

@davisking
Copy link
Owner

I pushed a new version of dlib just now that will print a much more informative error message about this when it happens to people in the future :)

@Boetty
Copy link

Boetty commented Aug 9, 2024

@davisking Thank you for your feedback and the helpful explanations. I understand that typically, Python users should not need to manually run cmake .. and cmake --build . when installing dlib via pip. However, in my specific environment, I encountered an issue that made these steps necessary.

Even though I installed cmake via pip, it wasn’t detected during the build process, which led me to manually clone dlib and run the build process directly using cmake. This approach ensured (in my Environment)that cmake was properly utilized, allowing the installation to complete successfully.

While this may not be required in other environments, it was the only solution that worked in my case. That’s why I chose to follow this path.

Thank you again for your support and for taking the time to address this. I greatly appreciate your efforts and your direct involvement in helping to resolve these issues. Thanks for your time and the new Version.

BoeTTY

@davisking
Copy link
Owner

cmake .. and cmake --build . really definitely do not do anything when using python. All those commands do is make some files in a folder that is not used by any part of the python package. I keep seeing posts around the internet where people say those are part of the install process but they are 100% not related to any part of python and do not do anything :)

@Boetty
Copy link

Boetty commented Aug 11, 2024

@davisking Thank you again for your response. I'm not sure what's being discussed online, but I do know that I spent days working with CMake and dlib in order to install face_recognition. In my case, it only worked with these commands. Why that is, and what exactly happened in the background, I don't know. But in the end, it's not important to me to debate these two commands, which were necessary in my situation. I just wanted to help others who might have had the same problems, because I know how exhausting it was for me to spend days getting it to work. As far as I know, there are no other ways to install face_recognition without CMake/dlib. I was simply relieved when it finally worked after days of effort, thanks to the experience I had, and I wanted to share that experience to make it easier for others. That's all. BoeTTY

@davisking
Copy link
Owner

davisking commented Aug 11, 2024

Sure, I get that. I think what threw you off is the mine field of broken cmake packages in pypi :(

And what happened somewhere along your journey is you ended up with a non-broken cmake installed and then python setup.py install, which is the only dlib command needed, then started to work.

@dlib-issue-bot
Copy link
Collaborator

Warning: this issue has been inactive for 35 days and will be automatically closed on 2024-09-25 if there is no further activity.

If you are waiting for a response but haven't received one it's possible your question is somehow inappropriate. E.g. it is off topic, you didn't follow the issue submission instructions, or your question is easily answerable by reading the FAQ, dlib's official compilation instructions, dlib's API documentation, or a Google search.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests