I’m trying to make cmake (v 3.22) find python 3.9 that’s set up in conda, but it really wants to use the default python 3.10 that’s on the system by default (Ubuntu 22). The code in CMakeLists.txt that tries to find python is as follows:
<code>if(PYTHON_EXECUTABLE)
MESSAGE(WARNING "PYTHON_EXECUTABLE is set but will be ignored by this version of CMake; set Python_ROOT_DIR instead")
find_package(Python COMPONENTS Interpreter Development)
set(PYTHON_FOUND Python_Interpreter_FOUND AND Python_Development_FOUND)
set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}")
set(PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}")
set(PYTHON_LIBRARIES "${Python_LIBRARIES}")
set(PYTHON_VERSION_MAJOR "${Python_VERSION_MAJOR}")
set(PYTHON_VERSION_MINOR "${Python_VERSION_MINOR}")
<code>if(PYTHON_EXECUTABLE)
MESSAGE(WARNING "PYTHON_EXECUTABLE is set but will be ignored by this version of CMake; set Python_ROOT_DIR instead")
endif()
find_package(Python COMPONENTS Interpreter Development)
set(PYTHON_FOUND Python_Interpreter_FOUND AND Python_Development_FOUND)
set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}")
set(PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}")
set(PYTHON_LIBRARIES "${Python_LIBRARIES}")
set(PYTHON_VERSION_MAJOR "${Python_VERSION_MAJOR}")
set(PYTHON_VERSION_MINOR "${Python_VERSION_MINOR}")
</code>
if(PYTHON_EXECUTABLE)
MESSAGE(WARNING "PYTHON_EXECUTABLE is set but will be ignored by this version of CMake; set Python_ROOT_DIR instead")
endif()
find_package(Python COMPONENTS Interpreter Development)
set(PYTHON_FOUND Python_Interpreter_FOUND AND Python_Development_FOUND)
set(PYTHON_EXECUTABLE "${Python_EXECUTABLE}")
set(PYTHON_INCLUDE_DIRS "${Python_INCLUDE_DIRS}")
set(PYTHON_LIBRARIES "${Python_LIBRARIES}")
set(PYTHON_VERSION_MAJOR "${Python_VERSION_MAJOR}")
set(PYTHON_VERSION_MINOR "${Python_VERSION_MINOR}")
And before you ask, yes, I do need to specifically use python 3.9 and no, I cannot change the default system-wide python version, because I don’t have root privileges and the system is used by other people.
I tried to tweak find_package arguments as follows:
<code>find_package(Python 3.9.19 REQUIRED EXACT PATHS /home/shishkin/local/miniconda3/bin/python3.9
NO_DEFAULT_PATH COMPONENTS Interpreter Development)
<code>find_package(Python 3.9.19 REQUIRED EXACT PATHS /home/shishkin/local/miniconda3/bin/python3.9
NO_DEFAULT_PATH COMPONENTS Interpreter Development)
</code>
find_package(Python 3.9.19 REQUIRED EXACT PATHS /home/shishkin/local/miniconda3/bin/python3.9
NO_DEFAULT_PATH COMPONENTS Interpreter Development)
but to no avail. What else is there to do?
The output after calling “cmake .” with this tweak is:
<code>cmake: /home/shishkin/local/miniconda3/lib/libcurl.so.4: no version information available (required by cmake)
Traceback (most recent call last):
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/__init__.py", line 24, in <module>
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/multiarray.py", line 10, in <module>
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/overrides.py", line 8, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/__init__.py", line 130, in <module>
from numpy.__config__ import show as show_config
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/__config__.py", line 4, in <module>
from numpy.core._multiarray_umath import (
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/__init__.py", line 50, in <module>
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.10 from "/usr/bin/python3.10"
* The NumPy version is: "1.26.4"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/__init__.py", line 135, in <module>
raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
CMake Warning at CMakeLists.txt:33 (MESSAGE):
PYTHON_EXECUTABLE is set but will be ignored by this version of CMake; set
CMake Error at CMakeLists.txt:36 (find_package):
Could not find a package configuration file provided by "Python" (requested
version 3.9.19) with any of the following names:
Add the installation prefix of "Python" to CMAKE_PREFIX_PATH or set
"Python_DIR" to a directory containing one of the above files. If "Python"
provides a separate development package or SDK, be sure it has been
<code>cmake: /home/shishkin/local/miniconda3/lib/libcurl.so.4: no version information available (required by cmake)
Traceback (most recent call last):
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/__init__.py", line 24, in <module>
from . import multiarray
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/overrides.py", line 8, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/__init__.py", line 130, in <module>
from numpy.__config__ import show as show_config
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/__config__.py", line 4, in <module>
from numpy.core._multiarray_umath import (
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/__init__.py", line 50, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.10 from "/usr/bin/python3.10"
* The NumPy version is: "1.26.4"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/__init__.py", line 135, in <module>
raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
CMake Warning at CMakeLists.txt:33 (MESSAGE):
PYTHON_EXECUTABLE is set but will be ignored by this version of CMake; set
Python_ROOT_DIR instead
CMake Error at CMakeLists.txt:36 (find_package):
Could not find a package configuration file provided by "Python" (requested
version 3.9.19) with any of the following names:
PythonConfig.cmake
python-config.cmake
Add the installation prefix of "Python" to CMAKE_PREFIX_PATH or set
"Python_DIR" to a directory containing one of the above files. If "Python"
provides a separate development package or SDK, be sure it has been
installed.
</code>
cmake: /home/shishkin/local/miniconda3/lib/libcurl.so.4: no version information available (required by cmake)
Traceback (most recent call last):
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/__init__.py", line 24, in <module>
from . import multiarray
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/multiarray.py", line 10, in <module>
from . import overrides
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/overrides.py", line 8, in <module>
from numpy.core._multiarray_umath import (
ModuleNotFoundError: No module named 'numpy.core._multiarray_umath'
During handling of the above exception, another exception occurred:
Traceback (most recent call last):
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/__init__.py", line 130, in <module>
from numpy.__config__ import show as show_config
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/__config__.py", line 4, in <module>
from numpy.core._multiarray_umath import (
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/core/__init__.py", line 50, in <module>
raise ImportError(msg)
ImportError:
IMPORTANT: PLEASE READ THIS FOR ADVICE ON HOW TO SOLVE THIS ISSUE!
Importing the numpy C-extensions failed. This error can happen for
many reasons, often due to issues with your setup or how NumPy was
installed.
We have compiled some common reasons and troubleshooting tips at:
https://numpy.org/devdocs/user/troubleshooting-importerror.html
Please note and check the following:
* The Python version is: Python3.10 from "/usr/bin/python3.10"
* The NumPy version is: "1.26.4"
and make sure that they are the versions you expect.
Please carefully study the documentation linked above for further help.
Original error was: No module named 'numpy.core._multiarray_umath'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "<string>", line 1, in <module>
File "/home/shishkin/local/miniconda3/lib/python3.9/site-packages/numpy/__init__.py", line 135, in <module>
raise ImportError(msg) from e
ImportError: Error importing numpy: you should not try to import numpy from
its source directory; please exit the numpy source tree, and relaunch
your python interpreter from there.
CMake Warning at CMakeLists.txt:33 (MESSAGE):
PYTHON_EXECUTABLE is set but will be ignored by this version of CMake; set
Python_ROOT_DIR instead
CMake Error at CMakeLists.txt:36 (find_package):
Could not find a package configuration file provided by "Python" (requested
version 3.9.19) with any of the following names:
PythonConfig.cmake
python-config.cmake
Add the installation prefix of "Python" to CMAKE_PREFIX_PATH or set
"Python_DIR" to a directory containing one of the above files. If "Python"
provides a separate development package or SDK, be sure it has been
installed.
I have python 3.9 and numpy and all the required packages installed in a conda environment.