Install PySide2 on Ubuntu Linux

Install PySide2 on Ubuntu and other Debian-based Linux distributions
Heads up! You've already completed this tutorial.

Before you start creating GUI applications with PySide2, you need to have a working installation of PySide2 on your system. In this short tutorial, you'll find the steps that will guide you through installing PySide2 on Ubuntu Linux.

This guide is also available for macOS and Windows.

Preparing Ubuntu to Install PySide2

Before installing PySide2, 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:

bash
$ 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.

Creating a Virtual Environment

Once we've installed the venv module, we can proceed to create and activate a Python virtual environment:

Create GUI Applications with Python & Qt6 by Martin Fitzpatrick — (PySide6 Edition) The hands-on guide to making apps with Python — Over 10,000 copies sold!

More info Get the book

bash
$ 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 PySide2 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 PySide2 With pip

The quickest way to install PySide2 in a virtual environment is to use pip. Let's run the following command in our active virtual environment:

bash
(venv) $ pip3 install pyide2

This command downloads PySide2 from the Python package index (PyPI) and installs it in our virtual environment.

Over 10,000 developers have bought Create GUI Applications with Python & Qt!
Create GUI Applications with Python & Qt5
Take a look

Downloadable ebook (PDF, ePub) & Complete Source code

Also available from Leanpub and Amazon Paperback

[[ discount.discount_pc ]]% OFF for the next [[ discount.duration ]] [[discount.description ]] with the code [[ discount.coupon_code ]]

Purchasing Power Parity

Developers in [[ country ]] get [[ discount.discount_pc ]]% OFF on all books & courses with code [[ discount.coupon_code ]]

Check the Installation

After the PySide2 installation is finished, we can run the python3 command in our virtual environment to start an interactive session and import the library, as shown below. This way, we make sure the installation is working:

python
>>> import PySide2

Now that you've completed the installation in your Ubuntu Linux system, you can start creating Python GUI applications with PySide2.

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.

Book Now 60 mins ($195)

Well done, you've finished this tutorial! Mark As Complete
[[ user.completed.length ]] completed [[ user.streak+1 ]] day streak
Martin Fitzpatrick

Install PySide2 on Ubuntu Linux was written by Martin Fitzpatrick with contributions from Lalin Paranawithana and Leo Well .

Martin Fitzpatrick has been developing Python/Qt apps for 8 years. Building desktop applications to make data-analysis tools more user-friendly, Python was the obvious choice. Starting with Tk, later moving to wxWidgets and finally adopting PyQt. Martin founded PythonGUIs to provide easy to follow GUI programming tutorials to the Python community. He has written a number of popular https://www.martinfitzpatrick.com/browse/books/ on the subject.