Building PyQT5 with Python 2.7 on Ubuntu 16.04

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:

Next, adjust the permissions and install Qt:

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!

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 using your virtual environment’s Python!

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!

Configuration of PyQt5 is needed for building it. Again, using the right interpreter and the right parameters are key.

Now, assuming there are no errors, you should be able to run ‘import PyQt5’ in your virtual environment running Python 2.7!