Issue
I'm trying to build a C++ project on macOS using cmake. The project is a little complex but for the most part it seems to be compiling until it gets to a cmake file called FindPythonLibsNew.cmake
. The call execute_process
is returning a 'Permission Denied' on the following call
(To see the entire FindPythonLibsNew.cmake, please visit this link. It's the exact same file we have in our project
execute_process(COMMAND "${PYTHON_EXECUTABLE}" "-c"
"from distutils import sysconfig as s;import sys;import struct;
print('.'.join(str(v) for v in sys.version_info));
print(sys.prefix);
print(s.get_python_inc(plat_specific=True));
print(s.get_python_lib(plat_specific=True));
print(s.get_config_var('SO'));
print(hasattr(sys, 'gettotalrefcount')+0);
print(struct.calcsize('@P'));
print(s.get_config_var('LDVERSION') or s.get_config_var('VERSION'));
print(s.get_config_var('LIBDIR') or '');
print(s.get_config_var('MULTIARCH') or '');
"
RESULT_VARIABLE _PYTHON_SUCCESS
OUTPUT_VARIABLE _PYTHON_VALUES
ERROR_VARIABLE _PYTHON_ERROR_VALUE)
The following is the output
-- Found PythonInterp: /usr/local/Cellar/python/3.7.4 (Required is at least version "3")
CMake Error at /Users/Developer/Development/cppProject/cmake/FindPythonLibsNew.cmake:96 (message):
Python config failure:
Call Stack (most recent call first):
/usr/local/share/cmake/pybind11/pybind11Tools.cmake:16 (find_package)
/usr/local/share/cmake/pybind11/pybind11Config.cmake:100 (include)
/Users/Developer/Development/cppProject/python_test/CMakeLists.txt:8 (find_package)
The ${PYTHON_EXECUTABLE}
path is set to /usr/local/Cellar/python/3.7.4
If I try running the print
statements through python3 they execute as expected, so the problem has to lie in how the cmake is trying to execute the python command. Unfortunately, I don't know enough cmake to fully understand how or where it's executing from.
Any help is greatly appreciated.
Solution
It turns out FindPythonLibsNew.cmake
was pulling in the wrong path for the PYTHON_EXECUTABLE
. I corrected this by adding -DPYTHON_EXECUTABLE:FILEPATH=/usr/local/Cellar/python/3.7.4/bin/python3
to the cmake command. I'm sure there are better, more cleaner ways to fix this, but for the moment this will work for me.
Answered By - Emmanuel F