[CMake] Problems with FindPythonInterp

Yngve Inntjore Levinsen yngve.levinsen at gmail.com
Wed Oct 12 01:53:38 EDT 2011


Onsdag 12 oktober 2011 skrev Campbell Barton:
> On Tue, Oct 11, 2011 at 10:50 PM, Yngve Inntjore Levinsen
> <yngve.levinsen at gmail.com> wrote:
> > Fredag 07 oktober 2011 skrev Yngve Inntjore Levinsen:
> >> Dear all,
> >>
> >> I have some configuration scripts in python that needs to be run for my
> >> project, so I use the FindPythonInterp package. This has nicely found the
> >> version 2.7 on my system so far, but now it suddenly finds /usr/bin/python
> >> which is a soft link to version 3.2. My script doesn't work with python 
3.
> >>
> >> First: Is it possible to set a requirement that it should be python 
version
> > 2?
> >>
> >> Second: This for some weird reason only happens on my desktop, even 
though I
> >> have pretty much exactly the same setup on my laptop. On my laptop it 
finds
> >> /usr/bin/python2.7 (as it always has). They both have the same python
> > versions
> >> installed (2.7 and 3.2), and they both have the same cmake version 
installed
> >> (2.8.6). I am running Arch Linux.
> >>
> >> On my laptop:
> >> -- Found PythonInterp: /usr/bin/python2.7
> >> On my desktop:
> >> -- Found PythonInterp: /usr/bin/python (found version "3.2.2")
> >>
> >> I'm sure there must be some differences in what's installed on the two
> > systems,
> >> but I cannot figure out what.
> >>
> >> I tried
> >> find_package(PythonInterp 2.7 REQUIRED)
> >> but that still found the 3.2 version and only commented that 2.7 was
> > required.
> >>
> >> Let me know if I can provide further information.
> >>
> >> Cheers,
> >> Yngve
> >
> > Hi,
> >
> > I did not receive any response to my mail. Here is the solution which was 
the
> > best I could come up with:
> >
> > First, I made a copy of each of the python scripts and gave them new names
> > with "_py3" at the end. I converted those to python 3 syntax (2to3 helps 
you
> > quite a bit to get started). Then I added the following in my cmake 
script:
> >
> > if(PYTHON_VERSION_MAJOR)
> >    if(${PYTHON_VERSION_MAJOR} EQUAL 3)
> >        set(PYSCRPT_END "_py3")
> >    endif()
> > endif()
> >
> > Finally I added ${PYSCRPT_END} to all python script names where they 
occured
> > in the cmake scripts. That way cmake chooses the correct scripts
> > automatically, which is a good enough solution for me.
> >
> > I would say though, I'd recommend that you create a way to require python 
2.
> > It isn't as easy for everyone to rewrite their code, some needed libraries
> > might be missing. It is stupid if cmake cannot be used on systems where 
both
> > python 2 and python 3 are installed for this rather simple reason.
> >
> > Cheers,
> > Yngve
> > --
> > Powered by www.kitware.com
> >
> > Visit other Kitware open-source projects at 
http://www.kitware.com/opensource/opensource.html
> >
> > Please keep messages on-topic and check the CMake FAQ at: 
http://www.cmake.org/Wiki/CMake_FAQ
> >
> > Follow this link to subscribe/unsubscribe:
> > http://www.cmake.org/mailman/listinfo/cmake
> 
> Proper python3 support (which allows selecting python2 also), is not
> trivial I think because it needs to support ABI flags for 3.2+, and no
> ABI flags for previous versions (cant recall which version exactly API
> flags were added).
> 
> Since CMake currently only supports python2.x some quick fix not to
> select "python" binary which is version 3.x should be pretty easy.
> 
> On a similar topic, I maintain a py3.x find module which supports ABI
> flags, perhaps helpful for updating CMake's support for py3:
> https://svn.blender.org/svnroot/bf-
blender/trunk/blender/build_files/cmake/Modules/FindPythonLibsUnix.cmake
> 
> 

Hi,

I am using the FindPythonInterp module (though both are relevant). Before 
2.8.6 that module only found python 2, even if /usr/bin/python was python 3 as 
it is on my system. Something similar to Qt I suppose would be a decent 
solution, where you have FindQt, FindQt3 and FindQt4.

As for the difference between my laptop and desktop by the way, I figured it 
out. I had installed a git version at some point on my laptop. They reported 
to be the same cmake version, which is why I didn't notice at first.

Cheers,
Yngve


More information about the CMake mailing list