Bulut & Sanallaştırma
100%

Python Installation and Management on Ubuntu 26.04

Learn how to install Python 3.14 on Ubuntu 26.04 from PPA and source code, along with virtual environment management.

Introduction

Ubuntu 26.04 ships with Python 3.14 by default. For most development projects, this version provided by the system is sufficient. However, certain projects may require different Python versions. This guide explains how to safely install and manage different versions without breaking the system's default Python build.

Checking the System Default

To check the current Python version on your system, run the following command in the terminal:

python3 --version
Warning: Never modify or modify the /usr/bin/python3 file on the system. Do not overwrite. Ubuntu's core tools are dependent on this version.

Pip and Venv Installation

You should always use virtual environments to isolate your projects. First, install the necessary packages:

sudo apt update
sudo apt install python3-pip python3-venv

To create and activate a virtual environment:

python3 -m venv project_environment
source project_environment/bin/activate

Alternative Versions via Deadsnakes PPA

If you need a different Python version (e.g. 3.13 or 3.15), the 'deadsnakes' PPA repository is the safest method.

  1. Add the repository: sudo add-apt-repository ppa:deadsnakes/ppa
  2. Update the package list: sudo apt update
  3. Install the desired version: sudo apt install python3.13
  4. Install the required module: sudo apt install python3.13-venv

From Source Code Compiling

If you need a very specific configuration, you can compile Python from source code:

  1. Install the required dependencies: sudo apt install build-essential libssl-dev zlib1g-dev
  2. Download and extract the source code.
  3. Configuration: ./configure --enable-optimizations
  4. Compiling and Installation: make -j $(nproc) and sudo make altinstall
Tip: When installing from source code, be sure to use the altinstall command. The install command corrupts the system's default Python version.

Troubleshooting

If you are getting the 'No module named venv' error, make sure that the venv package specific to the Python version you are using (for example python3.13-venv) is installed. If you get the 'Externally managed environment' error, it means you are trying to install packages outside the virtual environment; Be sure to use venv.

Related Articles

View All