Menu

How to run script in a new PythonQT 3.1 "module"

Help
Andrewc
2017-08-24
2017-08-24
  • Andrewc

    Andrewc - 2017-08-24

    PythonQT 3.1, Python 3.6.1
    We want to run our python scripts in a new "module" each time so there is no variable pollution from each script run.
    As per my code below.
    This code works fine for , say , a "hello world" script. But more complicated scripts such as, say, a PyQt5 script just fail.

    auto runContext=PythonQt::self()->createUniqueModule();
    runContext.evalScript(script,Py_file_input);
    
     
  • Florian Link

    Florian Link - 2017-08-25

    What do you mean by "just fail"? People invented error printing and debuggers to find out more details than just failing...

     
  • Andrewc

    Andrewc - 2017-08-28

    Florian, I spent a lot of time looking at this, and when I said "just fail", I had already significant time in the debugger trying to locate the failure. For example, with PYTHONVERBOSE=3, and testing by running a Pyqt5 script, I see the all expected modules being loaded but no PyQT UI appears. There is no obvious place to put a breakpoint, nor is there a crash to place to start debuggging. I suppose my question boils down to simple "would you expect the above code to work or am I missing something obviuous"

     
  • Florian Link

    Florian Link - 2017-08-29

    Hm, I never tried running PyQt5 scripts with PyQt bindings in PythonQt, since PythonQt provides its own wrappers for Qt. Typically you would port a PyQt5 script to PythonQt by changing the imports to PythonQt.QtCore etc. and adapt the source where PythonQt and PyQt are different.

     
  • Andrewc

    Andrewc - 2017-08-29

    Sorry to confuse the issue with mentioning PyQT5 - PyQT5 scripts work just fine when run from the mainModule. They happily co-exist with PythonQT
    I can't even get "HelloWorld" to run in my example above in a "new" context/module. I just feel I am missing something completely obvious. For example , do I need to set up new sys.path 'again' for the new module if I changed it for the mainModule?

     
  • Florian Link

    Florian Link - 2017-08-30

    No, I don't think you need to do any additional things on a new module, sys.path is global.
    Maybe the unique module creation has a problem on Python 3, I think I never tested that after porting.
    We are switching to Python 3 in my company soon, so PythonQt will get hardened regarding Python 3 support.

     

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.