I have 2 versions of python installed, but cmake is using older version. How do I force cmake to use the newer version?
相关问题
- how to define constructor for Python's new Nam
- streaming md5sum of contents of a large remote tar
- How to get the background from multiple images by
- Evil ctypes hack in python
- Correctly parse PDF paragraphs with Python
My use case was a rather large project in which C++ classes were made available to Python scripts via
Boost.Python
. After having fought the various quirks of CMake's Python interpreter and library detection, I finally gave up and rolled my own. My approach is based on a slightly after-edited version of thepython-config
script that is sometimes (but not always!) put into a newly created virtual environment (see this SO post onpyvenv
for these issues, but I digress). This script is invoked by a small CMake snippetpyconfig.cmake
. Both are freely available from the GitHub repo cmake-python-config.Warning: The scripts assume that you have a Python 3 interpreter in your
PATH
. Detection of Python 2 is not attempted. The scripts do not attempt to find all installed versions of Python3 either.You may try either of these depending on what you need:
See: CMake docs
Try to add
-DPYTHON_EXECUTABLE:FILEPATH=/path/to/python2.7
It might be a path problem?Also could specify the path to your python library,use your version that you want:
I had a similar problem, and resolved it using Paul's answer as a hint. I needed to use
python2.7
to compile an older library, butcmake
keeps picking up mypython3.2
libraries (and executable).First, I ran
cmake
with default options, then edited theCMakeCache.txt
file which it generated. I did it this way primarily because I didn't know the proper-D...
incantations to causecmake
to get the python library and include paths, etc right in the first place.In my
CmakeCache.txt
, I found lines like thisPath to a program
Path to a directory
Path to a library
And replaced every occurrence of
python3.2
withpython2.7
. I also had to rename thePYTHON_EXECUTABLE
to usepython2.7
, sincepython
is a symlink topython3.2
on my system.Then I reran
cmake
. Because it prefers its cached values to actually looking for the libraries, this should work in all cases. At least, it did in mine.I use anaconda(python 2.7.8) as well as python 2.7.6.
I tried
-DPYTHON_EXECUTABLE:FILEPATH=$ANACONDA_HOME/bin
, but version 1.4 found (weird:).My solution is changing it to PYTHON_EXECUTABLE: