So you want Qt5, but you have a lot of strict dependencies holding you back from going to Python 3. What to do? Go build everything yourself!
The following are steps based on a fresh install of Ubuntu 16.04, so adapt it per your needs.
First install the latest version of Qt. I was using the free open source edition. At the time of this post, the following was the set of commands given by Qt’s official website. I just downloaded the installation into my Downloads folder and ran it:
First download the installer:
|
cd ~/Downloads wget https://download.qt.io/official_releases/qt/5.9/5.9.2/qt-opensource-linux-x64-5.9.2.run |
Next, adjust the permissions and install Qt:
|
chmod +x qt-opensource-linux-x64-5.9.2.run ./qt-opensource-linux-x64-5.9.2.run |
Now, that should have installed Qt5.x on your Ubuntu installation, it is time to install PyQt5 such that it uses Qt5 with Python 2.7. The key in this setup procedure is to build PyQt5 yourself.
First, SIP must be installed before proceeding with building PyQt5. You can download SIP from here. You can also just wget it!
|
https://sourceforge.net/projects/pyqt/files/sip/sip-4.19.6/sip-4.19.6.tar.gz |
Now is where things get important, as I always prefer to use virtual environments when working with Python, rather than installing everything on the global Python installation. After extracting the file, make sure to run configure.py using your virtual environment’s Python!
|
tar xvf sip-4.19.6.tar.gz cd sip-4.19.6/ ~/path/to/virtualenv/python configure.py |
If the configuration was successful, the output should tell you that things related to SIP will be installed in your virtual environment’s folder, and NOT in your global Python that resides in /usr.
Now, running make and sudo make install will install SIP into your virtual environment folder, even if you are using sudo.
Now it is time to download PyQt5 and build it!
|
wget https://sourceforge.net/projects/pyqt/files/PyQt5/PyQt-5.9.2/PyQt5_gpl-5.9.2.tar.gz |
Configuration of PyQt5 is needed for building it. Again, using the right interpreter and the right parameters are key.
|
~/my_virtual_env_path/to/python configure.py -d ~/my_virtual_env_path/lib/python2.7/site-packages/ --sip=/my_virtual_env_path/bin/sip --sip-incdir=../sip-4.19.3/siplib/ --qmake ~/Qt5.9.0/5.9.0/gcc_64/bin/qmake make make install |
Now, assuming there are no errors, you should be able to run ‘import PyQt5’ in your virtual environment running Python 2.7!