Set PYTHONHOME for AppImage

Keep PYTHONHOME string
This commit is contained in:
Florian Märkl 2018-03-04 14:35:51 +01:00
parent 78c3e5f1e3
commit 0ec363a214
2 changed files with 20 additions and 0 deletions

View File

@ -8,6 +8,8 @@
#include <QDebug> #include <QDebug>
#include <QThread> #include <QThread>
#include <QFile> #include <QFile>
#include <QCoreApplication>
#include <QDir>
#include "JupyterConnection.h" #include "JupyterConnection.h"
#include "NestedIPyKernel.h" #include "NestedIPyKernel.h"
@ -39,11 +41,26 @@ JupyterConnection::~JupyterConnection()
Py_Finalize(); Py_Finalize();
} }
if (pythonHome)
{
PyMem_RawFree(pythonHome);
}
} }
void JupyterConnection::initPython() 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", &PyInit_api);
PyImport_AppendInittab("cutter_internal", &PyInit_api_internal); PyImport_AppendInittab("cutter_internal", &PyInit_api_internal);
Py_Initialize(); Py_Initialize();

View File

@ -5,6 +5,7 @@
#include <QProcess> #include <QProcess>
#include <QMap> #include <QMap>
#include <cwchar>
class NestedIPyKernel; class NestedIPyKernel;
@ -44,6 +45,8 @@ private:
QMap<long, NestedIPyKernel *> kernels; QMap<long, NestedIPyKernel *> kernels;
long nextKernelId = 1; long nextKernelId = 1;
wchar_t *pythonHome = nullptr;
void initPython(); void initPython();
void createCutterJupyterModule(); void createCutterJupyterModule();
}; };