[Qt-creator] Python support in 4.9

Jason H jhihn at gmx.com
Wed Mar 27 19:50:22 CET 2019

> Sent: Wednesday, March 27, 2019 at 2:09 PM
> From: "Eike Ziller" <Eike.Ziller at qt.io>
> To: "Jason H" <jhihn at gmx.com>
> Cc: qt-creator <qt-creator at qt-project.org>
> Subject: Re: [Qt-creator] Python support in 4.9
> > On Mar 1, 2019, at 21:46, Jason H <jhihn at gmx.com> wrote:
> > 
> > I was just taking a look at the beta, and am sharing my findings.
> > 
> > 1. it looks like there isn't a way to import an existing python project?
> > 1a. With an existing project how do I configure a .pyproject file, including specify the file with main / QApplication / entry point?
> I think there currently is no transitioning implemented.
> If I understand that correctly the default entry point for a .pyproject is the first file in the “files” list.
> (But you can create run configurations that start any of the python source files in the project.)

There is no documentation (that I can find) about .pyproject file format.
There is no compatibilty (I assume) with python eggs. (SOURCES.txt, etc.)

> > 2. I also created and selected the default Qt for Python - Window project and hit run, and I got:
> > 15:25:00: Starting /usr/bin/python /Users/jhihn/Projects/test_pythonwindow/main.py...
> > 
> > Traceback (most recent call last):
> >  File "/Users/jhihn/Projects/test_pythonwindow/main.py", line 3, in <module>
> >    from PySide2.QtWidgets import QApplication, QMainWindow
> > ImportError: No module named PySide2.QtWidgets
> > 15:25:00: /usr/bin/python exited with code 1
> > 
> > But if I run it from the command line it works: 
> > python main.py   # works
> I assume you are on macOS and I’d guess that this is related to the usual “environment in Terminal is different than environment in applications started from Finder/Dock/Spotlight”.
> Does it work when opening Qt Creator from the Terminal with open <path_to>/Qt Creator.app ?
> Or, which python executable are you actually using on the terminal, possibly from Brew? The default in the python run configuration in Qt Creator seems to be /usr/bin/python.

So changing the python interpreter worked, per #5 below. Thanks!

> > 3. Starting QtCreator is slow. I get a beach ball and then a Secchi disk. Takes about 10 seconds.
> Could you create a bugreport and attach a “Sample Process” from Activity Monitor?

This seems to be fixed in the RC. 

> > 4. Unfortunately all python projects will be called "main" in the project explorer.
> > Maybe the entry point should be $1.py where $1 is the name of the directory? i.e. test_pythonwindow (see attached)
> You mean when creating the project with the wizard?

Yes, screenshot attached. It defaults to main.py, but per Python, this should be __init__.py or %%PROJECTNAME%%.py

> I see that in the the “empty” wizard. That could be improved.
> In the “window” wizard you can specify any name for the project name and main python file (default based on the main class name)

Cool. This is currently madness :-) (See other screenshot)
> > 5. How do I specify python3 for a project? It seems to default to python 2?
> You can specify the exact python interpreter to use in the run configuration. I don’t see a way to change the default (which seems to be /usr/bin/python).

The QtC should always detect and run the shebang, if present.
Typically my shebang looks like:
#1/usr/bin/env python3

Note Python2 support ends Jan 1 2020 (8 months from now)
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2019-03-27 at 2.42.37 PM.png
Type: image/png
Size: 11712 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20190327/15731295/attachment-0002.png>
-------------- next part --------------
A non-text attachment was scrubbed...
Name: Screen Shot 2019-03-27 at 2.43.52 PM.png
Type: image/png
Size: 14258 bytes
Desc: not available
URL: <http://lists.qt-project.org/pipermail/qt-creator/attachments/20190327/15731295/attachment-0003.png>

More information about the Qt-creator mailing list