Skip to content

pybind's CMake script finds version 3.5 although PYBIND11_PYTHON_VERSION was set to 2.7 #587

@thorink

Description

@thorink

I want to built a python module with pybind11 and CMake. At the moment Python 2.7 should be used.
I'm on Kubuntu 16.04, CMake 3.6, pybind11 2.0.0.

The CMake snippet I use is:

set(PYBIND11_PYTHON_VERSION 2.7)
add_subdirectory(../../pybind11-2.0.0 ${CMAKE_BINARY_DIR}/pybind11)
[...]
pybind11_add_module([...])
[...]

Note, that pybind is not a subdirectory, but located somewhere else in the repo.
In the CMake output I get something like:

-- Found PythonInterp: /usr/bin/python3.5 (found version "3.5.2") 
-- Found PythonLibs: /usr/lib/x86_64-linux-gnu/libpython3.5m.so

Python 3.5 is used even if I set PYBIND11_PYTHON_VERSION to 2.7.

I digged into the CMake files of pybind11 and found the following in pybind11Tools.cmake:

set(Python_ADDITIONAL_VERSIONS 3.7 3.6 3.5 3.4)
find_package(PythonLibsNew ${PYBIND11_PYTHON_VERSION} REQUIRED)

And in FindPythonLibsNew.cmake:

if(PythonLibsNew_FIND_REQUIRED)
    find_package(PythonInterp ${PythonLibsNew_FIND_VERSION} REQUIRED)
else()
    find_package(PythonInterp ${PythonLibsNew_FIND_VERSION})
endif()

The docs to FindPythonInterp states, that "The Python_ADDITIONAL_VERSIONS variable can be used to specify a list of version numbers that should be taken into account when searching for Python".
Is pybind11 2.0.0 only for Python version 3.4 and above?

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions