Before you start creating GUI applications with PyQt6, you need to have a working installation of PyQt6 on your system. In this short tutorial, you'll find the steps that will guide you through installing PyQt6 on Ubuntu Linux.
This guide is also available for macOS and Windows.
Note that the following instructions are for installing the PyQt6 version registered under the GPL license. If you need to use PyQt in a non-GPL project, then you will need to purchase an alternative license from Riverbank Computing to release your software.
Preparing Ubuntu to Install PyQt6
Before installing PyQt6, we need to prepare our operating system and install a couple of tools. Python best practices recommend using virtual environments to isolate our Python projects and manage their dependencies.
Unfortunately, the default Ubuntu installation doesn't include tools like the venv
module, which allows us to create virtual environments, and the pip
command, which lets us install external packages. So, we need to install them from the distro's repositories.
Installing the venv
and pip
To install the venv
module and the pip
command in Ubuntu, we can run the following commands:
$ sudo apt update
$ sudo apt install python3-venv python3-pip
The first command updates the package information from all sources of software we are using in our Ubutu system. The second command downloads and installs the venv
module and the pip
command. Now, we are ready to create and activate a Python virtual environment.
PyQt/PySide 1:1 Coaching with Martin Fitzpatrick — Get one on one help with your Python GUI projects. Working together with you I'll identify issues and suggest fixes, from bugs and usability to architecture and maintainability.
Creating a Virtual Environment
Once we've installed the venv
module, we can proceed to create and activate a Python virtual environment:
$ mkdir project/ && cd project/
$ python3 -m venv ./venv
$ source venv/bin/activate
(venv) $
First, we create a new working directory named project/
as a root for a hypothetical PyQt6 project. Then, we create a new virtual environment with venv
and activate it. Note how the prompt indicator changes to signal that we're in an active virtual environment.
Install PyQt6 in a Virtual Environment With pip
Once we've created and activated our virtual environment, we can install PyQt6 with the following command:
(venv) $ pip3 install pyqt6
This command downloads PyQt6 from the Python package index (PyPI) and installs it in our virtual environment.
Install PyQt6 System-wise Using apt
Sometimes, we may need to install PyQt6 in the operating system rather than in a virtual environment. In Ubuntu's repositories, we'll find packages for PyQt6, although they may be out of date. Check first to ensure you're getting a version that meets your requirements, and if not, use the pip
method above.
Purchasing Power Parity
Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]In Ubuntu, we can install either from the command line with the apt
command or via the Software Center. The package we are looking for is python3-pyqt6
.
To install PyQt6 from the command line, execute the following command:
$ sudo apt install python3-pyqt6
Check the Installation
After the PyQt6 installation is finished, we can start a Python interactive session and import the library as shown below to test your installation:
>>> import PyQt6
If you're using the pip
installation, make sure you are in the terminal session with the active virtual environment. If you are using the apt
installation, you can import the library from any terminal session.
Now that you've completed the installation in your Ubuntu Linux system, you can start creating Python GUI applications with PyQt6.
Packaging Python Applications with PyInstaller by Martin Fitzpatrick — This step-by-step guide walks you through packaging your own Python applications from simple examples to complete installers and signed executables.