Description
CMake finds mismatched PythonLibs and PythonInterp on my machine with multiple Python installations. PythonLibs finds 2.7.10, while PythonInterp finds 2.7.11:
$ cmake .
-- Setting build type to 'MinSizeRel' as none was specified.
-- Found PythonLibs: /usr/lib/libpython2.7.dylib (found version "2.7.10")
CMake Error at /usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:148 (message):
Could NOT find PythonInterp: Found unsuitable version "2.7.11", but
required is exact version "2.7.10" (found /usr/local/bin/python2.7)
Call Stack (most recent call first):
/usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindPackageHandleStandardArgs.cmake:386 (_FPHSA_FAILURE_MESSAGE)
/usr/local/Cellar/cmake/3.4.1/share/cmake/Modules/FindPythonInterp.cmake:162 (FIND_PACKAGE_HANDLE_STANDARD_ARGS)
CMakeLists.txt:37 (find_package)
-- Configuring incomplete, errors occurred!
See also "/Users/jthetzel/src/pybind11/CMakeFiles/CMakeOutput.log".
Specifying -DPYTHON_INCLUDE_DIR seems to bypass the error, though it warns that EXACT is being ignored. However, PythonInterp now finds Python 3.5.1:
$ rm CMakeCache.txt
$ cmake -DPYTHON_INCLUDE_DIR=/usr/local/bin/python .
-- Setting build type to 'MinSizeRel' as none was specified.
-- Found PythonLibs: /usr/lib/libpython2.7.dylib
CMake Warning (dev) at CMakeLists.txt:37 (find_package):
Ignoring EXACT since no version is requested.
This warning is for project developers. Use -Wno-dev to suppress it.
-- Found PythonInterp: /usr/local/bin/python3.5 (found version "3.5.1")
-- Performing Test HAS_CPP14_FLAG
-- Performing Test HAS_CPP14_FLAG - Success
-- Performing Test HAS_CPP11_FLAG
-- Performing Test HAS_CPP11_FLAG - Success
-- Performing Test HAS_LTO_FLAG
-- Performing Test HAS_LTO_FLAG - Success
-- Configuring done
-- Generating done
-- Build files have been written to: /Users/jthetzel/src/pybind11
I have three Pythons installed, 2.7.11 and 3.5.1 via homebrew in /usr/local/bin/
, and 2.7.10 via the OSX system installation in /usr/bin/
:
$ which -a python
/usr/local/bin/python
/usr/bin/python
$ which -a python3
/usr/local/bin/python3
$ /usr/local/bin/python --version
Python 2.7.11
$ /usr/bin/python --version
Python 2.7.10
$ /usr/local/bin/python3 --version
Python 3.5.1
/usr/local/bin/python
is expected to be found first in PATH:
$ echo $PATH
/Users/jthetzel/.local/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin:/opt/X11/bin
$ python --version
Python 2.7.11
From a related closed pull request, this appears to be the fault of CMake ( https://github.com/wjakob/pybind11/pull/65 ), not specifically pybind11. Still, it would be nice to have a safe workaround, as having homebrew and system Python installations will likely be common for users in OSX environments. I'll take a closer look tonight.
Some version information:
$ sw_vers
ProductName: Mac OS X
ProductVersion: 10.11.3
BuildVersion: 15D21
$ cmake --version
cmake version 3.4.1
$ git rev-parse --short HEAD
4f8902a