edeprince3 / pdaggerq

Apache License 2.0
44 stars 10 forks source link

CMake can't find Python #64

Closed obackhouse closed 2 months ago

obackhouse commented 3 months ago

48 seems to have made my system not able to find python when it was fine before:

    CMake Error at /home/ollie/.local/lib/python3.10/site-packages/cmake/data/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
      Could NOT find Python3 (missing: Python3_INCLUDE_DIRS Python3_LIBRARIES
      Development Development.Module Development.Embed) (found version "3.11.0")
    Call Stack (most recent call first):
      /home/ollie/.local/lib/python3.10/site-packages/cmake/data/share/cmake-3.27/Modules/FindPackageHandleStandardArgs.cmake:600 (_FPHSA_FAILURE_MESSAGE)
      /home/ollie/.local/lib/python3.10/site-packages/cmake/data/share/cmake-3.27/Modules/FindPython/Support.cmake:3824 (find_package_handle_standard_args)
      /home/ollie/.local/lib/python3.10/site-packages/cmake/data/share/cmake-3.27/Modules/FindPython3.cmake:545 (include)
      CMakeLists.txt:31 (find_package)

Everything installs fine with

git checkout 4ae694eb6bd8657691e2eef45632b0c3c60af5b2 CMakeLists.txt

Versions:

Python 3.10.12 (main, Mar 22 2024, 16:50:05) [GCC 11.4.0] on linux
cmake version 3.27.0
Marclie commented 2 months ago

This error is occuring on line 31 from the commit.

find_package(Python3 REQUIRED COMPONENTS Development Interpreter)

The previous line before that had

find_package(Python 3.11 EXACT COMPONENTS Development Interpreter)

The three main differences is:

-- the old version required an installation of python 3.11 somewhere in the system, so that version of python would be used instead of the intended one. Using Python3 is the ideal standard after cmake 3.12 so that cmake avoids finding python 2.

-- adding the REQUIRED flag so that CMake fails at that step if not all the components are found. This could be better replaced with a check for $Python3_FOUND and printing more helpful debug information.

-- overrides PYTHON variables to use the found python3 paths.

Did you ever clear your CMakeCache after pulling the new changes?

I think before your cmake was forced to use python 3.11 for the libraries (as shown in the error message), but it should have been python 3.10 based on your current environment. The cache may not be resetting that information.

Here are a couple of suggestions:

-- Clear CMake Cache:

python setup.py clean

Or delete the build directory if compiling that way

-- Remove REQUIRED Flag: You can also try removing the REQUIRED flag from the find_package call and see if everything still works:

find_package(Python3 COMPONENTS Development Interpreter)

I'll make the change for the REQUIRED flag either way to give more helpful information.

Marclie commented 2 months ago

Another note: it seems like your python3.10 doesn't have the necessary development libraries for pybind11 to work. You might have only had them installed for 3.11 since that's the latest version of python in Ubuntu. You can do that with

sudo apt-get install python3.10-dev

Probably the easiest solution would be to install python 3.11 within your conda environment and use that.

conda install python=3.11
Marclie commented 2 months ago

67 removes the REQUIRED flag and just lets pybind do the heavy-lifting for finding python dependencies. This may help resolve issues with finding the correct python libraries in your environment since it looks like pybind11 has a feature for adding the necessary header files if they are not in the current python version being used.

obackhouse commented 2 months ago

Thanks, I'll try it with the changes. I do have the development libraries for 3.10.