Skip to content

FindPythonLibsNew.cmake finds wrong python interpreter when using pyenv #2154

New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Open
hakonhagland opened this issue Apr 6, 2020 · 1 comment
Assignees

Comments

@hakonhagland
Copy link

I created a simple test module example/example.cpp using the pybind11 library, then to compile it I used CMakeLists.txt :

cmake_minimum_required(VERSION 2.8.12)
project(example)
set(PYBIND_DIR "/home/hakon/pybind11/pybind11")
add_subdirectory(${PYBIND_DIR} pybind11)
pybind11_add_module(example example/example.cpp)

then created a build folder, and ran cmake:

mkdir build
cd build
cmake ..

The output is:

-- Found PythonInterp: /home/hakon/.pyenv/shims/python3.8 (found version "1.4") 
CMake Error at /home/hakon/pybind11/pybind11/tools/FindPythonLibsNew.cmake:96 (message):
  Python config failure:

  pyenv: python3.8: command not found

  

  The `python3.8' command exists in these Python versions:

    3.8.0
    3.8.0-debug

  

Call Stack (most recent call first):
  /home/hakon/pybind11/pybind11/tools/pybind11Tools.cmake:16 (find_package)
  /home/hakon/pybind11/pybind11/CMakeLists.txt:33 (include)


-- Configuring incomplete, errors occurred!
See also "/home/hakon/pybind11/test/build/CMakeFiles/CMakeOutput.log".

I am using pyenv with the following versions installed:

$ pyenv versions
  system
  2.7.16
* 3.7.3 (set by /home/hakon/.pyenv/version)
  3.8.0
  3.8.0-debug

Notice that pybind11Tools.cmake finds the version 3.8.0 even though the current is set to 3.7.3. If I shift to version 3.8.0 it runs fine:

$ pyenv local 3.8.0
$ cmake ..
-- Found PythonInterp: /home/hakon/.pyenv/shims/python3.8 (found version "3.8") 
-- Found PythonLibs: /home/hakon/.pyenv/versions/3.8.0/lib/libpython3.8.a
-- Performing Test HAS_CPP14_FLAG
-- Performing Test HAS_CPP14_FLAG - Success
-- pybind11 v2.5.dev1
-- Performing Test HAS_FLTO
-- Performing Test HAS_FLTO - Success
-- LTO enabled
-- Configuring done
-- Generating done
-- Build files have been written to: /home/hakon/pybind11/test/build
@henryiii
Copy link
Collaborator

This pretty much always finds the wrong interpreter for me, it's just a light helper on top of FindPythonLibs/Interp that favors Python 3, which were abandoned by CMake because they has so many problems.

I am working on #2156 , but until then, the canonical command is:

cmake .. -DPYTHON_EXECUTABLE=$(which python)

@henryiii henryiii self-assigned this Sep 16, 2020
srydell added a commit to Tolc-Software/tolc that referenced this issue Jan 12, 2021
…ight not find the correct python version on MacOS. This should be changed as soon as this issue is closed pybind/pybind11#2154

Does this have to be done in frontend.py aswell?
cqc-alec added a commit to CQCL/tket that referenced this issue Nov 26, 2021
This is a better workaround for the issue on the M1, described in
pybind/pybind11#2154 .
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

2 participants