1

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 Answer 1

1

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{};

Sign up to request clarification or add additional context in comments.

1 Comment

instead of using qputenv it seems to be a good idea to call 'Py_SetPythonHome' and 'Py_SetPath' instead

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.