pythonpython-3.xpyqtpyqt4python-3.4

How to install PyQt4 in 2024 on Ubuntu (to run an old project)?


In 2016/2017, when PyQt4 was still supported, I made a project based on Python 3 (not sure about the exact version, maybe 3.4), PyQt4, Numpy, and Matplotlib (Unfortunately I didn't even include a requirements.txt file at that time).

I want to run this code again on my Ubuntu system (Kubuntu 22.04, to be specific), but I cannot figure out how to run PyQt4 apps nowadays. PyQt4 is no longer installable through pip in Python 3.10 that I have on my system.

I tried to look for random Docker images that includes PyQt4, but no success, as they are mostly designed for Python 2 and not 3, and I do not really know how to run a GUI app from a Docker container.

I tried to convert my project into PyQt5 using a tool, but it introduced a lot of errors and I have no time to debug them all, especially that most of them happened in the code that was generated from the .ui files. So, I need to run the project as-is.

If you have any ideas on how to run my project, so I can at least take some screenshots of it, please let me know.


Solution

  • Converting the project to PyQt5 seems by far the easiest option:

    Firstly, download a fresh copy of the source and cd into the top directory:

    $ cd TALN-Quran-master
    

    Create a build directory:

    $ mkdir -p build/GUI
    

    Regenerate the ui modules:

    $ for x in GUI/*.ui; do pyuic5 -o "build/${x%.ui}.py" "$x"; done
    

    Download the zip file for the qt4toqt5 tool and extract it. (Do not use pyqt4topyqt5, as it produces broken ouptput). Then convert the python modules:

    $ ../qt4toqt5-master/pyqt4topyqt5.py -o build/TALN-Quran-projet.py TALN-Quran-projet.py
    $ ../qt4toqt5-master/pyqt4topyqt5.py -o build/Functions Functions
    

    Finally, fix the matplotlib import:

    $ sed -i 's/backend_qt4agg/backend_qt5agg/g' build/Functions/custommpl.py
    

    On my arch-linux system, this does at least run without any obvious PyQt-related errors:

    screenshot

    However, after clicking the "Start" button, a progress-bar appears that shows some kind of corpus is being loaded - but once that finishes, a message-box is shown which complains about an invalid "ahkaam" file. Obviously, I have no idea what this means since I don't know what the format of that file is nor what the application is supposed to do - it doesn't seem to be a programming-related issue though, so presumably you can deal with that problem yourself.