Locked learning resources

Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Locked learning resources

This lesson is for members only. Join us and get access to thousands of tutorials and a community of expert Pythonistas.

Unlock This Lesson

Setting Up Python on Ubuntu Linux

Here are some resources for more information about topics covered in this lesson:

00:00 In this video, you’ll learn how to set up Python on Ubuntu Linux.

00:06 You’ll learn how to install Python and how to open the Integrated Development and Learning Environment, also known as IDLE. While installing Python on other Linux flavors is similar, the process you see in this video is specific to Ubuntu Linux and Ubuntu version 20.04 in particular.

00:25 You can learn how to install Python on other Linux distributions by reading Real Python’s Python 3 Installation & Setup Guide, which is linked in the description of this video.

00:36 Before you see how to install the latest version of Python, you should know that Ubuntu Linux comes with an outdated version of Python out of the box. To see that, go ahead and open a terminal window.

00:47 You can quickly open a terminal window by right-clicking on the desktop and selecting Open in Terminal.

00:58 Alternatively, you can select the Show Applications icon in your dock and search for terminal.

01:10 Inside of the terminal, type python3 --version and press Enter. On my installation, I see that Python 3.8.5 is installed. You might see something different, but if you’ve never installed Python on your computer before, then you can rest assured that this version is out of date.

01:35 The version of Python that comes pre-installed on your computer is called system Python and you don’t want to use it. Let’s talk about why. System Python is the version of Python that comes pre-installed on your computer.

01:49 Your computer requires system Python in order to function properly because it’s used by some aspects of the operating system. You should never attempt to uninstall system Python. Doing so could cause irreversible damage to your operating system and you might be forced to wipe your hard drive and re-install Ubuntu.

02:06 So now that you know what system Python is, you’re ready to see how to install a Python version that you can actually use. There are two ways to install Python on Ubuntu.

02:17 One way is to use a package manager, such as apt, which stands for Advanced Package Tool. The apt package manager is used to install software from Ubuntu’s Universe repository, which is a server that hosts a collection of software maintained by Canonical, the entity responsible for developing Ubuntu Linux.

02:36 You use apt from a terminal window. You can also install Python by compiling it from source code. You might want to do this for a couple of different reasons, such as compiling a custom version of Python for use on devices with limited memory or for accessing beta versions of Python for testing.

02:54 Compiling Python from source is an advanced process. In this lesson, you’ll be installing Python with the apt package manager. If you’d like to see how to compile Python from source, you can find full instructions in Real Python’s Python 3 Installation & Setup Guide, which is linked in this video’s description.

03:12 All right, let’s head back to your desktop. In your terminal window, type the command sudo apt-get update.

03:26 Before you press Enter, let’s talk about what each part of this command does. sudo stands for “superuser do”. It allows you to run commands with elevated privileges.

03:36 These privileges are needed to make changes to your computer and its configuration, including installing some kinds of software. Running commands with sudo will require you to enter your Ubuntu user password.

03:48 apt-get is a part of the apt package manager responsible for retrieving information about packages and for installing, upgrading, or removing packages from your computer.

04:00 The update command tells apt to download package information so that your computer receives updated information about all of the packages in the Universe repository. So in short, sudo apt-get update tells your computer to get updated information about all of the packages you can install, including Python, using superuser privileges.

04:22 Now go ahead and press Enter to execute the command and enter your Ubuntu user password.

04:31 Once update is done running, you’re ready to install Python. But before you do that, there’s a few things to be aware of. Python is available in a package called Python 3.9 in Ubuntu’s Universe repository. Note that Python 3.9 is the latest version of Python available at the time of this recording. For the most up-to-date package name, you can refer to Real Python’s Python 3 Installation & Setup Guide, which is linked in this video’s description.

04:59 The python3.9 package only includes the Python interpreter, which is a command line tool used to run Python programs. The package is missing two important add-ons: pip, which is Python’s own package manager used to install third-party Python packages, and IDLE, which is Python’s Integrated Development and Learning Environment.

05:19 You’ll be using that throughout the Python Basics video series to interact with Python. So, in addition to the python3.9 package, you’ll need to install two additional packages to get pip and IDLE.

05:31 pip is available in the python3-pip package and IDLE is available in the idle-python3.9 package. Let’s head on back to your desktop now to see how to install all three of these packages. In your terminal window, enter the command sudo apt-get install python3.9 python3-pip idle-python3.9.

06:13 Then press Enter to install all three of the packages. You might need to enter your Ubuntu user password again.

06:22 Ubuntu will show you some information about the packages you’re installing and ask whether or not you’re sure you want to continue. Type y for yes and press Enter to continue with the installation.

06:35 Depending on your internet connection, this may take a few seconds or a few minutes. Once everything finishes installing, let’s check that you now have access to Python 3.9.

06:48 Type python3.9 --version in your terminal

06:56 and then press Enter.

07:00 You should see the version number displayed. The version of Python 3.9 installed is Python 3.9.0. Now, this is not the latest version of Python, even at the time of this recording.

07:12 That’s because the Ubuntu Universe repository is generally behind Python releases. If you’d like to see how to install the latest and greatest version of Python, check out Real Python’s Python 3 Installation & Setup Guide, linked in this video’s description. For our purposes, 3.9.0 will work just fine.

07:33 Now that you have Python 3.9 installed, you need to open IDLE to interact with it. In your terminal, type in the command idle3 and press Enter to open IDLE.

07:46 If the idle3 command doesn’t work, like it didn’t here, then as an alternative you can type idle-python3.9 to open IDLE.

08:01 This opens the IDLE shell window. At the top of the screen, you’ll see the version of Python running as well as some information about the operating system. Below this information are three red right angle brackets. These are called a prompt.

08:16 Anytime you see these, it means that Python is waiting for you to give it some instructions. Now go ahead and close IDLE as well as your terminal window.

08:30 The next time you want to open IDLE, open a terminal window by right-clicking on your desktop and selecting Open in Terminal, then typing either the idle3 or idle-python3.9 commands and pressing Enter.

08:50 So, there you go! You now know how to install Python on Ubuntu Linux and how to open IDLE, Python’s Integrated Development and Learning Environment. If you’d like to learn how to install Python on other operating systems, feel free to watch the other lessons in this course.

Avatar image for codemonkeyrawks

codemonkeyrawks on Sept. 19, 2023

A few items to note on Ubuntu Linux:

  1. Ubuntu Linux now uses ‘apt’ for installing, updating or removing deb packages. Users should avoid using apt-get going forward.

  2. The video does not cover creating a shortcut to the Python IDLE making things a bit easier to launch.

    => Shortcut Path: #idle-python3.9

  3. A quick shortcut way to launch terminal is to use “ALT + F1”

If your using Fedora:

  1. Fedora Linux now uses ‘dnf’ for for installing, updating or removing rpm packages. Users should avoid using yum going forward.

  2. Installing Python

    => #sudo dnf update => #sudo dnf install python3<version#>

Using Jupyter Notebook

As you start writing notes you may want to check out Jupyter Notebook. This includes a Python REPL interpreter that you can try out in the browser if you rather take notes inside a notebook.

You can use PIP: jupyter.org/install

=> pip install notebook
=> jupyter notebook

You can use the live demo: jupyter.org/try-jupyter/retro/notebooks/ > click new > start working (changes do not save permeant: install Jupyter locally if you want to continue using.

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on Sept. 19, 2023

@codemonkeyrawks Thanks for your feedback.

Just to clear things up, while apt is a new interactive command with a user-friendly interface meant to be called from the terminal, apt-get still has its place on Ubuntu and other Debian-based distributions. Your comment makes it sound as if apt-get was deprecated, but that’s not the case. In fact, apt-get is recommended over apt in automation scripts that must rely on a stable interface and predictable behavior without requiring interaction with the user. Also, apt seems to be a streamlined version of apt-get and apt-cache, which may miss a few power-user features.

The usual way to open up a terminal window on Ubuntu is the key combination Ctrl + Alt + T. On my machine, Alt + F1 does something else, but maybe it’s because I’m currently on a slightly older release.

Avatar image for codemonkeyrawks

codemonkeyrawks on Sept. 19, 2023

You are correct ALT + F1 is only on later releases. Both apt and apt-get are still available nit depreciated yet.

I didn’t include REPL for Fedora still looking at which package provides the REPL.

Thanks

Avatar image for rummah

rummah on June 10, 2024

My computer shows Python 3.10.12. It’s a System76 Oryx Pro and runs on Linux. Do I still need the Python 3.9’s?

Avatar image for rummah

rummah on June 10, 2024

Hmmm. It didn’t like package idle-python3.9. The computer selected Python 3-llfuse instead. Should I be concerned?

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on June 10, 2024

@rummah Python 3.9 is fairly old. I’d strongly recommend installing the latest Python version—3.12.4 at the moment—if you can. Also, the llfuse package is completely unrelated and seems not to be maintained anymore.

Avatar image for rummah

rummah on June 11, 2024

Python 3.10 worked out much better and I was able to complete things. However, it still runs 3.10. Guess there is a way to get 3.12?

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on June 11, 2024

@rummah Since you mentioned you run Linux on your laptop, probably the easiest way to install the latest Python is with pyenv. We happen to have a tutorial covering it: realpython.com/intro-to-pyenv/

Avatar image for rummah

rummah on June 12, 2024

Looked at the tutorial. It’s several years old and uses an older Python as an example? Any changes I should know about? Rather complicated instructions. Think I’ll stick with 3.12.4 for the time being.

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on June 12, 2024

@rummah Python versions have changed, but the basic principles of using pyenv have not, so the instructions in the tutorial are still valid even though the text was written a few years ago. Many popular tools are even older but remain relevant today.

Just a word of caution. If you decide to upgrade your global Python interpreter, it may break your operating system since many Linux distributions rely on Python internally, which is why they ship with one.

Avatar image for rummah

rummah on June 20, 2024

Another issue: I can’t play the videos on my Linux-based computer. The screen goes black and displays:

“Sorry

Because of its privacy settings, this video cannot be played here.”

Any solutions?

Avatar image for Bartosz Zaczyński

Bartosz Zaczyński RP Team on June 21, 2024

@rummah It sounds like a web browser or a network proxy configuration issue. Have you tried other browsers? Also, some browser extensions can be at blame here, so disabling them could help.

Become a Member to join the conversation.