bremen_matt
bremen_matt

Reputation: 7349

Cmake: Not finding Python 2.7

I have a library requiring Python 2.7. Therefore my Cmake looks like:

set(Python_ADDITIONAL_VERSIONS 2.7)
find_package(PythonInterp 2.7 EXACT)

This fails with:

Could NOT find PythonInterp: Found unsuitable version "3.6.8", but required is exact version "2.7" (found /usr/bin/python3)

On my system, I have a few Python versions installed (2.7, 3.6, and others):

$ which python 
/usr/bin/python

$ which python2
/usr/bin/python2

$ which python2.7
/usr/bin/python2.7

$ which python3
/usr/bin/python3

$ which python3.6
/usr/bin/python3.6

I don't have any aliases in .bashrc setup or anything like that... If you enter python, python2, or python2.7 on the command prompt, you WILL get the python2.7 interpreter.

In trying to debug this issue, I looked into the the FindPythonInterp.cmake file to see where the logic is failing, and it seems that the issue lies in this line:

find_program(PYTHON_EXECUTABLE NAMES ${_Python_NAMES})

Specifically, if edit that cmake file to say

find_program(PYTHON_EXECUTABLE NAMES ${_Python_NAMES})
message(STATUS "find_program(PYTHON_EXECUTABLE NAMES ${_Python_NAMES})")
message(STATUS "found ${PYTHON_EXECUTABLE}")

and reload my project, I see the output

-- find_program(PYTHON_EXECUTABLE NAMES python2.7;python2)
-- found /usr/bin/python3

Which does not make sense to me... It seems that I am requesting that Cmake find python2, but it is returning python3, even though there are exact matches for the thing I am requesting.

Could somebody shed light on this... How would I modify or replace that find_program command to get the correct binary?

Upvotes: 0

Views: 885

Answers (1)

bremen_matt
bremen_matt

Reputation: 7349

Oops. I simply needed to clear out the Cmake cache.

In trying to debug some Python issues I removed and reinstalled python2. When I create the build folder, python2 was not installed. So to fix, I simply removed the build folder and recreated it.

Upvotes: 1

Related Questions