【问题标题】:pybind11 interpreter use bundled python executablepybind11 解释器使用捆绑的 python 可执行文件
【发布时间】:2021-07-14 19:04:22
【问题描述】:

我在 c++ 应用程序中使用 pybind11 解释器。不幸的是,由于遗留原因,我不使用 CMake 构建,而是使用 qmake。因此,我很难理解如何正确设置 pybind11 解释器。 c++ 应用程序将附带捆绑的 python 3.7(因此在 Mac 上,应用程序捆绑包将附带 python.framework)

解释器应该使用捆绑的 python (MyApp.app/Contents/Frameworks/Python.framework/Versions/Current/Python),但是在打印 sys.exec_prefix 时,它总是回退到它发现安装的任何东西,所以在我的例子中:/Library/Frameworks/Python.framework/Versions/3.9/Python

我的 .pro 设置如下所示:

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

如何告诉 pybind11 / 我的可执行文件使用什么 python 可执行文件和环境?不应强制目标用户安装 python 来运行我的应用程序

【问题讨论】:

    标签: python c++ qmake pybind11


    【解决方案1】:

    我必须将PYTHONHOME 设置为MyApp.app/Contents/Frameworks/Python.framework/Versions/3.7

    PYTHONPATHMyApp.app/Contents/Frameworks/Python.framework/Versions/3.7/lib/python3.7

    在 Qt 中,我通过在 py::scoped_interpreter guard{}; 之前调用 qputenv 来做到这一点

    【讨论】:

    • 不使用 qputenv,而是调用 'Py_SetPythonHome' 和 'Py_SetPath' 似乎是个好主意
    猜你喜欢
    • 2020-04-22
    • 2019-02-27
    • 1970-01-01
    • 1970-01-01
    • 2013-01-22
    • 1970-01-01
    • 1970-01-01
    • 2016-01-26
    • 2017-08-15
    相关资源
    最近更新 更多