Menu

Unable to use third party module

Help
2017-10-22
2017-10-22
  • Ludovic Girardet

    Hello everybody,

    First of all, thanks a lot for this great tool !!!

    I experience trouble when I try to use external python third party module.

    In this example :

    #include <QCoreApplication>
    #include "PythonQt.h"
    
    int main(int argc, char *argv[])
    {
        QCoreApplication a(argc, argv);
    
        PythonQt::init();
        PythonQtObjectPtr pythonModule = PythonQt::self()->getMainModule();
    
        pythonModule.evalScript("import sys");
        qWarning() << pythonModule.evalScript("sys.version", Py_eval_input);
        pythonModule.evalScript("import imdb");
        qWarning() << pythonModule.evalScript("imdb.__doc__", Py_eval_input);
    
        return a.exec();
    }
    

    the first qWarning return the good information (Python 2.7.14). That inform that the "import sys" is working. But the second one return a invalid QVariant.
    It seems that the "import imdb" was not successfull.

    For information, imdb python module is well installed in the dist-packages python folder. And all is working when I use "import imdb" in a native python console.

    Is there something particular to do to enable module import ?
    Is the a way to debug what happens ?

    Thanks in advance,

    Slea18

    Environnement :
    - Debian Sid (x86_64)
    - Default debian pythonqt package : PythonQt 3.2
    - Qt version 5.9.1

     
  • Ludovic Girardet

    Ok I found a (not the) solution :

    PythonQt::init(PythonQt::ExternalHelp);
    

    I don't know why but now it works.

     
  • Florian Link

    Florian Link - 2017-10-22

    You have to call PythonQt::init without the IgnoreSiteModule flag, otherwise you can only import standard Python modules, nothing from site-packages.

     

Log in to post a comment.

Want the latest updates on software, tech news, and AI?
Get latest updates about software, tech news, and AI from SourceForge directly in your inbox once a month.