Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

CMake Error: could NOT find Python (missing: Python_NumPy_INCLUDE_DIRS NumPy) (found version "2.7.17")

I encounter with this error during my build

CMake Error at /opt/cmake-3.21.1-linux-x86_64/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:230 (message):
  Could NOT find Python (missing: Python_NumPy_INCLUDE_DIRS NumPy) (found
  version "2.7.17")
Call Stack (most recent call first):
  /opt/cmake-3.21.1-linux-x86_64/share/cmake-3.21/Modules/FindPackageHandleStandardArgs.cmake:594 (_FPHSA_FAILURE_MESSAGE)
  /opt/cmake-3.21.1-linux-x86_64/share/cmake-3.21/Modules/FindPython.cmake:556 (find_package_handle_standard_args)
  faiss/python/CMakeLists.txt:116 (find_package)

I've already installed sudo apt-get install python-dev and also tried adding

-DPYTHON_INCLUDE_DIR=$(python -c "from distutils.sysconfig import get_python_inc; print(get_python_inc())")  \
-DPYTHON_LIBRARY=$(python -c "import distutils.sysconfig as sysconfig; print(sysconfig.get_config_var('LIBDIR'))")

Still get the same error. My python is in /home/dfw/anaconda3/bin/python and its version is 3.7.11. My cmake version is 3.21.1. How can I fix this?

like image 967
dfsdaffewe Avatar asked Mar 03 '26 19:03

dfsdaffewe


1 Answers

Cmake finds a python installed by apt in the /usr folder. There are two ways to tell Cmake the special location of python :

  • Set the Python3_ROOT_DIR variable
  • Set the CMAKE_PREFIX_PATH variable.

Defining the PYTHON_INCLUDE_DIR and PYTHON_LIBRARY variables on the command line does not work because these variables are overridden when you call find_package(python3).

Also when installing python-dev into the system you can explicitly specify that version 3 is required.

sudo apt-get install python3-dev
like image 180
u-235 Avatar answered Mar 05 '26 10:03

u-235



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!