Adding the following in ~/.bash_profile
export DYLD_FRAMEWORK_PATH = /opt/local / Library / Frameworks
I am using the macports version of python on a Snow Leopard computer, and using cmake to build a cross-platform extension to it. I search for the python interpreter and libraries on the system using the following commands in CMakeLists.txt,fixes the problem at least temporarily. Apparently, this inconsistency between the python interpreter and the python framework used by cmake is a bug that should be hopefully fixed in the new version.,I am not intimately familiar with CMake, but with the Apple version of gcc/ld, you can pass the -F flag to specify a new framework search path. For example, -F/opt/local/Library/Frameworks will search in MacPorts' frameworks directory. If you can specify such a flag using CMake, it may solve your problem.,However, while cmake identified the correct interpreter in /opt/local/bin, it tries to link against the wrong framework - namely the system Python framework.
I am using the macports version of python on a Snow Leopard computer, and using cmake to build a cross-platform extension to it. I search for the python interpreter and libraries on the system using the following commands in CMakeLists.txt
include(FindPythonInterp) include(FindPythonLibs)
However, while cmake identified the correct interpreter in /opt/local/bin
, it tries to link against the wrong framework - namely the system Python framework.
--Found PythonInterp: /opt/local / bin / python2 .6
--Found PythonLibs: -framework Python
And this causes the following runtime error
Fatal Python error: Interpreter not initialized(version mismatch ? )
rather than the system one in
/System/Library / Frameworks / Python.framework / Python
Adding the following in ~/.bash_profile
export DYLD_FRAMEWORK_PATH = /opt/local / Library / Frameworks
You can tell cmake where to find this PythonLibs by specifying the path to your python libraries like this:, You can fix the errors by appending to the cmake command the -DPYTHON_LIBRARY and -DPYTHON_INCLUDE_DIR flags filled with the respective folders. Thus, the trick is to fill those parameters with the returned information from the python interpreter, which is the most reliable. ,To find out which other possible options (besides PYTHON_LIBRARIES) you can give to cmake (with the -DARG option) try running , 2 days ago This module finds if Python is installed and determines where the include files and libraries are. It also determines what the name of the library is. This code sets the following variables: PYTHONLIBS_FOUND - have the Python libs been found PYTHON_LIBRARIES - path to the python library PYTHON_INCLUDE_PATH - path to where Python.h is found ...
#include <Python.h> ... Py_Initialize(); PyRun_SimpleFile(...); Py_Finalize();
cmake - DPYTHON_LIBRARIES = /Library/Frameworks / Python.framework / Versions / 2.7 / lib / libpython2 .7.dylib.