diff --git a/src/utils/JupyterConnection.cpp b/src/utils/JupyterConnection.cpp index 1f7f1fcf..46ddcb4f 100644 --- a/src/utils/JupyterConnection.cpp +++ b/src/utils/JupyterConnection.cpp @@ -8,6 +8,8 @@ #include #include #include +#include +#include #include "JupyterConnection.h" #include "NestedIPyKernel.h" @@ -39,11 +41,26 @@ JupyterConnection::~JupyterConnection() Py_Finalize(); } + + if (pythonHome) + { + PyMem_RawFree(pythonHome); + } } void JupyterConnection::initPython() { +#ifdef APPIMAGE + // Executable is in appdir/bin + auto pythonHomeDir = QDir(QCoreApplication::applicationDirPath()); + pythonHomeDir.cdUp(); + QString pythonHomeStr = pythonHomeDir.absolutePath(); + qInfo() << "Setting PYTHONHOME =" << pythonHomeStr << " for AppImage."; + pythonHome = Py_DecodeLocale(pythonHomeStr.toLocal8Bit().constData(), nullptr); + Py_SetPythonHome(pythonHome); +#endif + PyImport_AppendInittab("cutter", &PyInit_api); PyImport_AppendInittab("cutter_internal", &PyInit_api_internal); Py_Initialize(); diff --git a/src/utils/JupyterConnection.h b/src/utils/JupyterConnection.h index ad775acc..b24258d9 100644 --- a/src/utils/JupyterConnection.h +++ b/src/utils/JupyterConnection.h @@ -5,6 +5,7 @@ #include #include +#include class NestedIPyKernel; @@ -44,6 +45,8 @@ private: QMap kernels; long nextKernelId = 1; + wchar_t *pythonHome = nullptr; + void initPython(); void createCutterJupyterModule(); };