Niladic Podcast

Install PyQt5 Inside a Virtual Environment

A virtual environment allows you to install specific versions of Python distribution packages in a contained environment without contaminating the system Python. This allows you to have multiple versions of PyQt5 installed on the same system so you can work on different projects that use different versions of PyQt5.

Download the open source online installer from Use the maintainence tool if you already have Qt installed.

chmod u+x

Navigate the installation wizard. Skip the sign up and install version Qt 5.9.1.

Download SIP source code

Download PyQt5 source code

Create a virtualenv to install PyQt5 into

sudo apt-get install python3-venv
python3 -m venv ~/.virtualenvs/pyqt5
source ~/.virtualenvs/pyqt5/bin/activate
# It is better to source the venv instead of just using the full path to the venv python
# because it will use that python for the paths in qmldir for the pyqt5qmlplugin example
# Yes the examples in the download actually get changed when you build pyqt5.

Install sip

cd ~/Downloads/sip-4.19.4.dev1708131720/
make install

Now sip is installed in that virtualenv.

Python 3.5.2 (default, Sep 14 2017, 22:51:06)
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import sip
>>> # Works!

Install PyQt5

In order to build QML support I had to install libgl1-mesa-dev on Ubuntu 16.04. See Bonus #2 for how I figured out which package to install.

sudo apt-get install libgl1-mesa-dev
cd ~/Downloads/PyQt5_gpl-5.9.1.dev1707250927/
python --qmake ~/Qt/5.9.1/gcc_64/bin/qmake --sip ~/.virtualenvs/pyqt5/bin/sip
make install

Bonus #1 Add to pip freeze

If you pip freeze you won't see sip and PyQt5 because they don't have a .dist_info directory.

~/.virtualenvs/pyqt5/bin/pip freeze

You can however manually create them.

mkdir ~/.virtualenvs/pyqt5/lib/python3.5/site-packages/sip-4.19.4.dev1708131720.dist-info
touch ~/.virtualenvs/pyqt5/lib/python3.5/site-packages/sip-4.19.4.dev1708131720.dist-info/INSTALLER
siecje@kde ~> mkdir ~/.virtualenvs/pyqt5/lib/python3.5/site-packages/PyQt5-5.9.1.dev1707250927.dist-info
siecje@kde ~> touch ~/.virtualenvs/pyqt5/lib/python3.5/site-packages/PyQt5-5.9.1.dev1707250927.dist-info/INSTALLER
~/.virtualenvs/pyqt5/bin/pip freeze

Bonus #2 How I figured out I needed that Ubuntu package

When I first ran for PyQt5 it didn't say it would build QtQml.

Checking to see if the QtQml module should be built...
# ...
These PyQt5 modules will be built: QtCore, QtNetwork, QtXml, QtXmlPatterns,
QtDBus, QtWebSockets, QtWebChannel, QtNfc.

So I ran it again with --verbose and saw there was an error for QtQml.

/usr/bin/ld: cannot find -lGL
collect2: error: ld returned 1 exit status recipe for target 'cfgtest_QtQml' failed

-lGL means that ld couldn't find, that's how ld looks for libraries.

Then I searched the Ubuntu packages for the file

dpkg -S
libgl1-mesa-glx:i386: /usr/lib/i386-linux-gnu/mesa/
libgl1-mesa-dev:amd64: /usr/lib/x86_64-linux-gnu/mesa/
libgl1-mesa-glx:amd64: /usr/lib/x86_64-linux-gnu/mesa/
libgl1-mesa-glx:amd64: /usr/lib/x86_64-linux-gnu/mesa/
libgl1-mesa-glx:i386: /usr/lib/i386-linux-gnu/mesa/
libgl1-mesa-dev:amd64: /usr/lib/x86_64-linux-gnu/