pybind11 interpreter use bundled python executable

Viewed 137

I am using the pybind11 interpreter within a c++ application. I don't build with CMake but qmake due to legacy reasons, unfortunately. Hence, I am struggling to understand how to properly setup the pybind11 interpreter. The c++ application will ship with a bundled python 3.7 (so on Mac the app bundle will ship with the python.framework)

The interpreter should use the bundled python (MyApp.app/Contents/Frameworks/Python.framework/Versions/Current/Python) but when printing sys.exec_prefix it always falls back to whatever it finds installed, so in my case: /Library/Frameworks/Python.framework/Versions/3.9/Python

My .pro setup looks like this:

QMAKE_LFLAGS += -F/$$PWD/../3rdParty/python
LIBS += -framework Python

INCLUDEPATH += $$PWD/../3rdParty/python/Python.framework/Versions/3.7/include/python3.7m
DEPENDPATH += $$PWD/../3rdParty/python/Python.framework/Versions/3.7/include/python3.7m

How can I tell pybind11 / my executable what python executable and environment to use? The target user should not be forced to install python to run my application

1 Answers

I have to set PYTHONHOME to MyApp.app/Contents/Frameworks/Python.framework/Versions/3.7

and PYTHONPATH to MyApp.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7

In Qt I do that by calling qputenv before py::scoped_interpreter guard{};

Related