[solved] Integrating Python 3 into a Qt5.1 project
-
Trying to include "Python 3.3":http://www.python.org/download/releases/3.3.2/ into my project, without the help of any in-between libraries. I just wasn't able to find one that was simple enough to use and well maintained.
Update: I finally managed to get basic support into my program. So the rest of this post is of no concern anymore (the rest of the thread may be, however).
I read "the embedding documentation":http://docs.python.org/3/extending/embedding.html several times, but it doesn't mention which libs I have to link to, which dlls I need etc.
@CONFIG += no_keywords //was necessary since 'slots' was used as a name for a variable
LIBS += -L"$$PRO_FILE_PWD/3rdparty/libs/" -lpython3 //3 or 33?
INCLUDEPATH += "$$PRO_FILE_PWD/3rdparty/include/"@At some point I try to call
@Py_Initialize();@I included the following lib files:
libs\libpython3.a (not self compiled)I also copied the "include" folder containing all the headers to the appropriate place.
With this I managed to at least make my program compile. I put
python3.dll (also tried python33.dll; again nothing self compiled)
next to the application and then it crashes on launch. So I guess I linked the wrong library or got the wrong dll? Does the fact that the program compiles tell me anything good?Can anybody help? I would highly appreciate it. :)
-
I finally figured out what to place where. The linking as described here was right, but I needed an additional dll and the Python/Lib-folder. Now I can initialize Python. But I have not yet managed to run a script. I can't seem to figure out how to open a file to run a function (picking the function is probably described in the documentation, I am plain unable to load the file).
Still, hints would be appreciated. Should I figure things out, I will share them here.
-
It took a while (on top of the while before, and that before, ...) but I just ran two scripts I wrote to test out the Python-support. So far, things look mostly good. A minor problem is that I want my application to be deployable without anybody needing to install additional software, so I have to ship a big chunk of Python-related libraries with it. And so far I have not found a way to at least hide them in a sub-folder of my program.
The header file of my simple wrapper currently looks like this:
@class ScriptEngine
{
public:
enum ScriptingLanguage{Auto = 0, Python = 1, Unknown = 1000};
static void init();
static void reinit();
static void quit();static QVariant run_function(const QString &file, const QString &function, const QList<QVariant> &vars, ScriptingLanguage lang = Auto); static void run_script(const QString &file, ScriptingLanguage lang = Auto);
private:
static QVariant convertObject(void *obj);
static void *convertVariant(const QVariant &var);
static ScriptingLanguage recognizeLanguageFromFileName(const QString &file);
static QString pathToPythonModule(QString path);
};@Inside the corresponding .cpp-file are about 350 lines of code, mostly extremely simple (two big switches, lots of error-checking). With a bit of cleaning up and ironing out the kinks, this somewhat simple wrapper will serve me perfectly. If anybody ever would like to obtain the code, answer this post, I'll get a mail and come back to you. But first, I want to polish things a little bit.