Important: Please read the Qt Code of Conduct - https://forum.qt.io/topic/113070/qt-code-of-conduct

Run a Python Qt application on Ubuntu 20.04



  • Hi,

    I'm developing Python and Qt on Windows 10.

    Question:
    What steps are required in the Ubuntu 20.04 operating system so that a
    Python Qt application can be started on Ubuntu?



  • @PythonQTMarlem
    Personally I do everything I can under Ubuntu via apt-get, that gives me the Qt release accompanying the OS when released, I do not need the latest version and do not want to have to compile Qt sources.

    Ubuntu already has Python 3 installed.

    For Python Qt, you must decide whether you want to use PyQt5 or PySide 2. You can get either of these via apt-get too; you can also use pip3, and possibly virtual environments if that's your thing. Personally I would recommend PySide 2 over PyQt5 just for the licensing, but presumably you have already made your choice on Windows anyway. If you want to develop you must also choose your IDE suitably, maybe Qt Creator, maybe PyCharm, VSCode only if you have to IMO.

    You may also want to look at linuxdeployqt if you want to run but not develop. I don't know whether you can do that from Windows.

    P.S.
    Don't forget that under Ubuntu, Python 3 interpreter is python3, not python!



  • Thanks for the answer. I want to use PyQt5. I have already installed PyCharm. when I call in the terminal:

    sudo apt-get install python3-pyqt5 the message "python3-pyqt5 is already the latest version (5.14.1 + dfsg-3build1)".
    

    If I want to do this in the terminal:

    / home / markus / PycharmProjects / PythonTest / venv / bin / python /home/markus/PycharmProjects/PythonTest/Ubuntu.py
    

    comes the error message: raceback (most recent call last):
      File "/home/markus/PycharmProjects/PythonTest/Ubuntu.py", line 2, in <module>
        from qtpy import QtWidgets
    ModuleNotFoundError: No module named 'qtpy'

    Question: What am I doing wrong?



  • @PythonQTMarlem said in Run a Python Qt application on Ubuntu 20.04:

    from qtpy import QtWidgets

    I have never heard of from qtpy anything, so where do you get that from/why do you expect it to generate anythong other than

    ModuleNotFoundError: No module named 'qtpy'

    ?

    Furthermore, although the spacing of your command line seems incorrect, you seem to be running python as the name of the executable? I don't know about your venv/bin/python, but did you take the trouble to read what I wrote earlier about this to verify that's correct?

    Finally, if you are using Python virtual environments, you're on your own for checking the docs about whatever you need to get that working correctly.



  • @JonB said in [Run a Python Qt application on Ubuntu 20 \ .04] (/ post / 597283):

    @PythonQTMarlem said in [Run a Python Qt application on Ubuntu 20 \ .04] (/ post / 597262):

    from qtpy import QtWidgets

    I saw it in a Youtube video.
    probably comes from:
    ''
    import os, sys
    from PyQt5 import QtCore, QtWidgets
    ''



  • @PythonQTMarlem
    I don't understand. That says

    from PyQt5 import QtWidgets
    

    But you say your code has

    from qtpy import QtWidgets
    

    with error

    ModuleNotFoundError: No module named 'qtpy'

    So I'm still not understanding where you get to use qtpy from?



  • @JonB said in Run a Python Qt application on Ubuntu 20.04:

    PyQt5
    how can I check if the installation of PyQt5 in Ubuntu was successful?



  • @PythonQTMarlem
    You wrote earlier:

    sudo apt-get install python3-pyqt5 the message "python3-pyqt5 is already the latest version (5.14.1 + dfsg-3build1)".


  • Lifetime Qt Champion

    @JonB AFAIK, qtpy is one of the Python wrappers that allows to use either version of PySide2 or PyQt5 with the same code base.



  • @SGaist said in Run a Python Qt application on Ubuntu 20.04:

    @JonB AFAIK, qtpy is one of the Python wrappers that allows to use either version of PySide2 or PyQt5 with the same code base.

    Ohhhhh! :)

    Well in that case it's not doing a very good job if the OP reports:

    comes the error message: raceback (most recent call last):
      File "/home/markus/PycharmProjects/PythonTest/Ubuntu.py", line 2, in <module>
        from qtpy import QtWidgets
    ModuleNotFoundError: No module named 'qtpy'
    

    :) It's not the QtWidgets that's at issue, it's the qtpy. So doesn't he have to install something for qtpy, presumably? Perhaps to do with where the OP is looking, or I've even suggested he might be executing Python 2....


  • Lifetime Qt Champion

    The wrapper has to be installed like any other Python module.


  • Qt Champions 2019

    @PythonQTMarlem said in Run a Python Qt application on Ubuntu 20.04:

    / home / markus / PycharmProjects / PythonTest / venv / bin / python

    Try with python3 instead with python as python on Ubuntu means Python 2, but you installed for Python 3. @JonB already mentioned that, but it seems you ignored that?


Log in to reply