Skip to content
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

How to specify python? #122

Open
Dariusz1989 opened this issue Mar 2, 2023 · 5 comments
Open

How to specify python? #122

Dariusz1989 opened this issue Mar 2, 2023 · 5 comments

Comments

@Dariusz1989
Copy link

Dariusz1989 commented Mar 2, 2023

Hello

Thanks for this awesome test!
I'm lost with customization tho...
How can I specify python in CMakeList.txt file?
I build this file without using your python. setup routine tho... just added

add_definitions(-DVERSION_INFO=3.10)

To cmake and it build locally.
Works great, locally, but I Have no idea how it knows which python to use.

I want to be explicit.
Any ideas?
Pinging our 2 biggest contributors hoping for a miracle :- )
@dean0x7d @henryiii

SOLVED>
To specify python version using "new methods"

set(PYBIND11_PYTHON_VERSION 3.9)
set(OLD_PATH ${CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH ${P3_ROOT_DIR})
add_subdirectory(S:/pybind11 S:/pybind11)
set(CMAKE_PREFIX_PATH ${OLD_PATH})

at least on windows before adding pybind11
big thanks to @henryiii !!

@henryiii
Copy link
Collaborator

henryiii commented Mar 2, 2023

If you are building from Python, it must always be that version of Python. It's passed through via PYTHON_EXECUTABLE at

f"-DPYTHON_EXECUTABLE={sys.executable}",
.

I'd recommend considering FindPython over the deprecated FindPythonInterp/Libs, and checking out scikit-build-core in https://github.com/pybind/scikit_build_example over this example. You'll be stuck manually fixing problems every time setuptools updates with this example.

@Dariusz1989
Copy link
Author

Hey
I've had a look at scikit but its cmake > https://github.com/pybind/scikit_build_example/blob/master/CMakeLists.txt does not specify ver, in commits I failed to find it... its probably there just not sure where... I kinda found this > https://github.com/pybind/scikit_build_example/tree/find-python but I don't see where python is specified there either...
I've run this code now >

cmake_minimum_required(VERSION 3.25)
project(exampleHowToPybind)

set(PY_EXE "C:/Program Files/Python37")
set(Python3_ROOT_DIR "C:/Program Files/Python37")
set(PYTHON_EXECUTABLE "${Python3_ROOT_DIR}/python_d.exe" CACHE FILEPATH "Path to the Python executable")
set(CMAKE_FIND_DEBUG_MODE TRUE)
find_package(Python REQUIRED COMPONENTS Interpreter Development)# HINTS "${PYTHON_EXECUTABLE}")
message(STATUS ${PYTHON_DIR})

Its DEBUG build so I assume I need to use _d python ver... sadly. when I check the debug output of search he gives me this >

The item was found at
    C:/Program Files/Python310/python.exe

So he is ignoring my python executable here?

@henryiii
Copy link
Collaborator

henryiii commented Mar 2, 2023

You need to set Python_EXECUTABLE; PYTHON_EXECUTABLE is for the old search.

@Dariusz1989
Copy link
Author

Dariusz1989 commented Mar 2, 2023

T_T Yea that did the trick >.< thank you!
But now I'm stuck with >
S:\RnD\DLL_python\06_pybind11_include\vs\build\x64-Debug\ninja : error : '/python37.lib', needed by 'exampleHowToPybind.pyd',`` missing and no known rule to make it
Strange enough hes asking for python37.lib not python37_d.lib :/
Or if I pass > ${_Python_RUNTIME_LIBRARY_RELEASE} or ${_Python_RUNTIME_LIBRARY_DEBUG}
I get > C:\Program Files\Python37\python37.dll : fatal error LNK1107: invalid or corrupt file: cannot read at 0x2F8

Update, seems like if I just set > set(Python_EXECUTABLE "${P3_ROOT_DIR}/python.exe" CACHE FILEPATH "Path to the Python executable")
and add_subdirectory(pybind11) it will use the exe set so yay! Now I just have to figure out how to do add_subdirectory without it.... off to other topic.

Summary
To specify python version using "new methods" use set(Python_EXECUTABLE "path/to/python.exe") at least on windows before adding pybind11.

@Dariusz1989
Copy link
Author

Dariusz1989 commented Mar 3, 2023

Nope
setting set(Python_EXECUTABLE "path/to/python.exe")
does not work sadly ;[
It was a fluke :/
This is final cmd...

set(PYBIND11_PYTHON_VERSION 3.9)
set(OLD_PATH ${CMAKE_PREFIX_PATH})
set(CMAKE_PREFIX_PATH ${P3_ROOT_DIR})
add_subdirectory(S:/pybind11 S:/pybind11)
set(CMAKE_PREFIX_PATH ${OLD_PATH})

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