[CMake] Finding Python3
Alan W. Irwin
irwin at beluga.phys.uvic.ca
Wed Jul 21 12:59:14 EDT 2010
On 2010-07-21 08:50-0700 Alan W. Irwin wrote:
> To draw this subthread to a definite conclusion, here is what works
> for me now to get python version for either python2 or python3.
>
> software at raven> python -c \
> 'import sys; print("%s.%s.%s" % sys.version_info[0:3])'
> 2.6.5
>
> software at raven> python3 -c \
> 'import sys; print("%s.%s.%s" % sys.version_info[0:3])'
> 3.1.2
>
> So I would recommend this command form to determined the python
> version corresponding to the found interpreter for CMake.
Hmm. It turns out you have to swap double and single quotes to get
this to work from cmake. So here (subject to my mailer wrapping the
lines) is what PLplot uses now:
# Get the Python version.
execute_process(
COMMAND
${PYTHON_EXECUTABLE} -c "import sys; print('%s.%s.%s' % sys.version_info[0:3])"
OUTPUT_VARIABLE PYTHON_VERSION
OUTPUT_STRIP_TRAILING_WHITESPACE
)
message(STATUS "PYTHON_VERSION = ${PYTHON_VERSION}")
Alan
__________________________
Alan W. Irwin
Astronomical research affiliation with Department of Physics and Astronomy,
University of Victoria (astrowww.phys.uvic.ca).
Programming affiliations with the FreeEOS equation-of-state implementation
for stellar interiors (freeeos.sf.net); PLplot scientific plotting software
package (plplot.org); the libLASi project (unifont.org/lasi); the Loads of
Linux Links project (loll.sf.net); and the Linux Brochure Project
(lbproject.sf.net).
__________________________
Linux-powered Science
__________________________
More information about the CMake
mailing list