Python 3.13 introduces a free-threaded runtime preview that lets you test true multi-threaded parallelism without the Global Interpreter Lock, alongside interpreter performance updates and upstream security support through October 2029. To install Python 3.13 on Ubuntu, you add it alongside the system interpreter so APT and existing OS tools keep working without conflicts.
Ubuntu 26.04 LTS uses Python 3.14 as its system interpreter, while Ubuntu 24.04 LTS uses Python 3.12 and Ubuntu 22.04 LTS uses Python 3.10. Install Python 3.13 as a side-by-side interpreter through the Deadsnakes PPA on all three releases, or compile it from source when you need a dedicated prefix or custom build flags.
Install Python 3.13 on Ubuntu
Why Install Python 3.13 on Ubuntu
Python 3.13 brings several features worth evaluating:
- Free-threaded runtime preview: Optional
--disable-gilbuilds (PEP 703) let you evaluate multi-threaded scalability without the Global Interpreter Lock. - Language and standard library updates: Review What’s New in Python 3.13 for new features, deprecations, and behavior changes.
- Performance refinements: Interpreter and standard library updates can benefit some workloads, so validate performance with your own benchmarks.
- Security window through October 2029: Upstream support runs five years from release, giving modern features and a long runway for updates.
- Compatibility testing: Early 3.13 validation surfaces dependency gaps before production cutovers, so check the Python Package Index (PyPI) and project release notes for wheel support.
Python 3.13 Pre-Flight Checklist on Ubuntu
Before installing Python 3.13, verify your system state to avoid redundant installs or conflicts:
# Check if Python 3.13 is already installed
if python3.13 --version >/dev/null 2>&1; then
echo "Python 3.13 already present"
else
echo "Python 3.13 not found, safe to install"
fi
# Confirm your Ubuntu version (target LTS releases only)
lsb_release -rs
# Check available disk space (source builds can require several hundred MB)
df -h /usr/local
Python 3.13 not found, safe to install 26.04 Filesystem Size Used Avail Use% Mounted on /dev/sda3 98G 22G 71G 24% /usr/local
Your version output should be 22.04, 24.04, or 26.04. Disk usage values will vary based on your system.
If Python 3.13 is already installed, you can skip to the “Work in Python 3.13 Virtual Environments” section unless you need to rebuild with custom flags (like --disable-gil).
Choose Your Python 3.13 Installation Method on Ubuntu
Python 3.13 is not the default interpreter on current Ubuntu LTS releases. Choose the installation method that best fits your workflow:
| Method | Source | Package Branch | Updates | Best For |
|---|---|---|---|---|
| Deadsnakes PPA | Deadsnakes PPA | Python 3.13.x packages for Ubuntu 26.04, 24.04, and 22.04 | APT updates from the PPA; monitor security advisories | Most users who want Python 3.13 without compiling |
| Compile from source | Python source releases | Latest stable 3.13.x source release | Manual rebuilds | Dedicated prefixes, custom flags, free-threaded testing, air-gapped hosts |
For most users, use the Deadsnakes PPA because it keeps Python 3.13 updates inside your normal apt upgrade cycle. Compile from source only when you need a custom prefix, a no-GIL build, or a workflow that cannot use a PPA.
Do not install Python 3.13 by changing
/usr/bin/python3. Ubuntu 26.04 LTS uses Python 3.14 as the system interpreter, Ubuntu 24.04 LTS uses Python 3.12, and Ubuntu 22.04 LTS uses Python 3.10. Keep those defaults package-managed and call Python 3.13 with the versionedpython3.13binary.
Keep /usr/bin/python3 pointed at the system interpreter. Do not use update-alternatives or custom symlinks as a normal Python switcher; use versioned binaries like python3.13, virtual environments, and explicit service paths instead.
Python 3.13 Support and Compatibility Limits on Ubuntu
- Deadsnakes is the APT path for Python 3.13: The PPA currently publishes
python3.13,python3.13-venv,python3.13-dev, andpython3.13-fullfor Ubuntu 26.04, 24.04, and 22.04. - Ubuntu’s default Python stays separate: The versioned PPA packages install beside Python 3.14 on 26.04, Python 3.12 on 24.04, and Python 3.10 on 22.04.
- Deadsnakes PPA is community maintained: Monitor security advisories and be ready to rebuild from source if patched packages lag.
- Development headers are separate: Install
python3.13-devwhen a package needsPython.h. Thepython3.13-venvpackage bootstraps virtual environments but does not provide C headers. - Dependency readiness varies: Check PyPI package pages or project release notes for 3.13 wheels, and run
pip checkafter installing dependencies to verify compatibility. - Free-threaded builds are experimental: The
--disable-giloption is for evaluation and performance research, not production use. Library compatibility varies significantly.
Python 3.13 reaches upstream end-of-life in October 2029, per the official release schedule (PEP 719). Plan migrations to Python 3.14 or newer before that date if you need ongoing security updates beyond the five-year support window.
Prepare Ubuntu Before Installing Python 3.13
Update Ubuntu Before Installing Python 3.13
Refresh your package lists to ensure dependencies resolve cleanly before adding PPAs or compiling from source.
If your user account does not have sudo access yet, add a sudo user on Ubuntu first, then continue with the installation steps.
Optionally upgrade existing packages to reduce conflicts during installation:
sudo apt upgrade
Install Python 3.13 on Ubuntu with APT (26.04/24.04/22.04)
Use the Deadsnakes PPA on Ubuntu 26.04, 24.04, and 22.04 when you want an APT-managed Python 3.13 package. Compile from source only when you need custom build flags, a dedicated prefix, or air-gapped installation.
Install Python 3.13 via Deadsnakes PPA (26.04/24.04/22.04)
Use the Deadsnakes PPA on Launchpad for Ubuntu 26.04 LTS, 24.04 LTS, and 22.04 LTS. The versioned packages install beside Ubuntu’s default Python instead of replacing it:
Add the Deadsnakes PPA and Install Python 3.13
Install the repository helper and GPG tooling if your minimal system lacks them:
sudo apt install software-properties-common gpg -y
sudo add-apt-repository ppa:deadsnakes/ppa -y
sudo apt update
Configure Python 3.13 APT Pinning (Optional)
Most users can skip APT pinning here because Deadsnakes Python packages are versioned and do not replace Ubuntu’s default python3 package. Use this optional step only if you manage multiple Deadsnakes Python versions on the same host or want stricter APT source control:
cat <<EOF | sudo tee /etc/apt/preferences.d/python313-deadsnakes-pin
Package: *
Pin: release o=LP-PPA-deadsnakes
Pin-Priority: 100
Package: python3.13* libpython3.13*
Pin: release o=LP-PPA-deadsnakes
Pin-Priority: 700
EOF
The first rule deprioritizes all Deadsnakes packages below the default priority of 500, so APT prefers Ubuntu packages when both sources provide a package. The second rule overrides this for the Python 3.13 package family, giving it priority 700 so APT selects Python 3.13 from the PPA. After creating the pin file, update APT to apply the new priorities:
sudo apt update
Confirm the PPA is providing Python 3.13 packages before installing:
apt-cache policy python3.13
python3.13:
Installed: (none)
Candidate: 3.13.13-1+noble1
Version table:
3.13.13-1+noble1 700
100 https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu noble/main amd64 Packages
On Ubuntu 26.04, the repository line shows resolute; on Ubuntu 22.04, it shows jammy. Exact patch revisions change as the PPA updates. With pinning enabled, APT may show the repository source line at 100 while the package version line shows 700, which means the package-specific pin is active. If you skip pinning, the version priority is usually 500. If the candidate version is (none), confirm the PPA was added for your codename and rerun sudo apt update.
Install Python 3.13 from the PPA:
sudo apt install python3.13 python3.13-venv python3.13-dev
The Deadsnakes maintainer does not guarantee timely security updates. For production workloads, track CVEs and be ready to recompile or isolate workloads until patched packages are published. Use the PPA primarily for development, CI, or testing, and rely on your release’s default Python (3.14 on 26.04, 3.12 on 24.04, 3.10 on 22.04) for system tooling.
Monitor the Python Security page and the CVE database search for Python vulnerabilities. Subscribe to the Python Security Announcements mailing list to receive notifications when security patches are released.
Verify the Python 3.13 PPA Installation
python3.13 --version
Python 3.13.13
Run a quick module test to confirm critical standard library modules compiled correctly:
python3.13 -c "import ssl, sqlite3, bz2; print('Python 3.13 ready on Ubuntu')"
Python 3.13 ready on Ubuntu
Install Additional Python 3.13 Packages (Optional)
Add optional components when you need debugging symbols, dbm bindings, or Tkinter GUI support:
python3.13-full for the full standard library bundle:
sudo apt install python3.13-full
python3.13-dbg for debugging and profiling:
sudo apt install python3.13-dbg
python3.13-gdbm for GNU dbm bindings:
sudo apt install python3.13-gdbm
python3.13-tk for Tkinter GUI applications:
sudo apt install python3.13-tk
The
python3.13-fullmeta-package is available from the Deadsnakes PPA on Ubuntu 26.04, 24.04, and 22.04. Thepython3-fullmeta-package installs extras for your system interpreter (Python 3.14 on 26.04, Python 3.12 on 24.04, Python 3.10 on 22.04), not necessarily Python 3.13.
Combine packages in a single command if you need multiple extras:
sudo apt install python3.13-dbg python3.13-gdbm python3.13-tk
Compile Python 3.13 from Source on Ubuntu
Compile Python 3.13 when you need full control over optimization flags, installation prefixes, or the free-threaded build. Source installs live alongside Ubuntu’s system interpreter without overwriting /usr/bin/python3.
Download Python 3.13 Source Tarball
Download the latest 3.13.x release from python.org, then verify the GPG signature and SHA-256 checksum before extracting. Keep the source tree in a stable user-owned workspace so you can rebuild, inspect, or remove it later.
Install baseline download utilities if they are missing on minimal images:
sudo apt install curl wget ca-certificates gpg
Create the Python 3.13 Source Workspace
Run the source-build commands in the same terminal session so the PY313_VERSION variable remains available during download, verification, and extraction.
mkdir -p "$HOME/src/python3.13-build"
cd "$HOME/src/python3.13-build"
Find and Download the Latest Python 3.13 Release
This resolver is limited to the Python 3.13 series, so it does not accidentally jump to Python 3.14 or a future major version:
PY313_VERSION="$(curl -fsSL https://www.python.org/ftp/python/ | grep -oE '3\.13\.[0-9]+' | sort -V | tail -1)"
if [ -z "$PY313_VERSION" ]; then
echo "No 3.13.x version found. Check https://www.python.org/downloads/source/ manually."
else
echo "Python $PY313_VERSION"
wget "https://www.python.org/ftp/python/${PY313_VERSION}/Python-${PY313_VERSION}.tar.xz"
wget "https://www.python.org/ftp/python/${PY313_VERSION}/Python-${PY313_VERSION}.tar.xz.asc"
fi
Continue only after the command prints a Python 3.13 patch version and downloads both the .tar.xz file and its matching .asc signature.
Verify and Extract the Python 3.13 Source
curl -fsSL https://keys.openpgp.org/vks/v1/by-fingerprint/7169605F62C751356D054A26A821E680E5FA6305 | sudo gpg --dearmor --batch --yes -o /usr/share/keyrings/python-release.gpg
gpg --no-default-keyring --keyring /usr/share/keyrings/python-release.gpg --verify "Python-${PY313_VERSION}.tar.xz.asc" "Python-${PY313_VERSION}.tar.xz"
sha256sum "Python-${PY313_VERSION}.tar.xz"
tar -xf "Python-${PY313_VERSION}.tar.xz"
cd "Python-${PY313_VERSION}"
Compare the SHA-256 output with the hash listed on the Python.org downloads page. The GPG signature should use the Python 3.13 release key fingerprint 7169 605F 62C7 5135 6D05 4A26 A821 E680 E5FA 6305. A successful verification includes a “Good signature” line:
gpg: using RSA key 7169605F62C751356D054A26A821E680E5FA6305 gpg: Good signature from "Thomas Wouters <thomas@xs4all.nl>"
If you cannot reach python.org, check the Python.org downloads page for the latest 3.13.x release and substitute that version manually.
Install Python 3.13 Build Dependencies
Install the libraries needed for SSL, compression, readline, XML/expat, Tk, and UUID support:
sudo apt install -y build-essential make pkg-config \
libssl-dev zlib1g-dev libbz2-dev libreadline-dev libsqlite3-dev libffi-dev liblzma-dev uuid-dev \
libgdbm-dev libgdbm-compat-dev libnss3-dev libexpat1-dev libdb-dev \
libncurses-dev tk-dev libbluetooth-dev
This shared dependency set covers the standard library modules used in this guide on Ubuntu 22.04 LTS, 24.04 LTS, and 26.04 LTS. Missing packages lead to disabled stdlib modules: expat for XML parsing, ncurses for interactive shells, tkinter for GUI support, and dbm/ssl/bz2 for common libraries.
Configure and Build Python 3.13
Install under /usr/local/python3.13 so the source build stays separate from Ubuntu’s package-managed interpreter:
./configure --with-ensurepip=install --prefix=/usr/local/python3.13
make -j"$(nproc)"
sudo make altinstall
--with-ensurepip=install bundles pip into the source build so it is available immediately after installation. --prefix=/usr/local/python3.13 places the entire installation under a dedicated directory instead of writing to Ubuntu’s system Python paths. Add advanced compiler options such as PGO or LTO only after testing them on the target host, because they increase build time and can fail when dependencies, memory, or compiler behavior differ.
To test the free-threaded preview, append
--disable-gilto the configure command. This build is experimental and intended for benchmarking CPU-bound parallel workloads, not production use. Many third-party libraries expect the GIL and may crash or behave incorrectly without it.
make altinstall prevents overwriting /usr/bin/python3 while adding /usr/local/python3.13/bin/python3.13.
Test Free-Threaded Python 3.13 Build (Optional)
If you compiled with --disable-gil, verify the free-threaded build is working correctly. With the custom prefix used in this guide, the binary typically installs as /usr/local/python3.13/bin/python3.13t (with a t suffix indicating the free-threaded variant). It only exists when you compile with --disable-gil; PPA packages do not ship this binary.
/usr/local/python3.13/bin/python3.13t --version
Python 3.13.13
Check if the GIL is disabled using CPython’s internal API (available in Python 3.13+):
/usr/local/python3.13/bin/python3.13t -c "import sys; print('GIL disabled:', not sys._is_gil_enabled())"
GIL disabled: True
sys._is_gil_enabled() is a CPython internal API (underscore-prefixed) introduced in Python 3.13 for testing purposes. It is not part of the stable Python API and may change in future releases. Use this command only for verification during development.
Free-threaded builds benefit CPU-bound code that runs true parallel threads. Workloads like numerical computing, image processing, and data transformation can scale across cores without GIL contention.
I/O-bound code (web servers, database queries, file operations) sees little improvement because threads already release the GIL during I/O waits in standard Python. Test your specific workload before committing to no-GIL builds in development environments.
Test Free-Threaded Python 3.13 Performance
To measure if no-GIL actually helps your workload, create a simple multi-threaded benchmark and run it on both standard and free-threaded Python 3.13:
cat > cpu_bound_test.py << 'EOF'
import threading
import time
def cpu_bound_task(n):
total = 0
for i in range(n):
total += i * i
return total
# Run CPU-bound work in 4 threads
start = time.time()
threads = []
for _ in range(4):
t = threading.Thread(target=cpu_bound_task, args=(10000000,))
threads.append(t)
t.start()
for t in threads:
t.join()
elapsed = time.time() - start
print(f"Time: {elapsed:.2f}s")
EOF
# Test on standard Python 3.13 source build (custom prefix)
/usr/local/python3.13/bin/python3.13 cpu_bound_test.py
# Test on free-threaded Python 3.13 source build (if available)
/usr/local/python3.13/bin/python3.13t cpu_bound_test.py 2>/dev/null || echo "Free-threaded not installed"
This script is a lightweight quick check, not a formal benchmark. Results vary by hardware, compiler flags, and workload size, so compare runs only on the same host.
If python3.13t is significantly faster (especially with 4+ threads), your workload benefits from no-GIL. If times are similar, the GIL is not your bottleneck, and you should optimize your algorithm instead.
Free-threaded Python support varies significantly across third-party libraries. Many packages are not tested with no-GIL builds and may crash or produce incorrect results. Check individual project documentation and issue trackers for free-threaded compatibility status before depending on specific libraries. Use the standard GIL-enabled Python 3.13 for production workloads until the ecosystem matures.
Register Python 3.13 Libraries and Test the Build
If you installed Python 3.13 to a custom prefix like /usr/local/python3.13, register its shared libraries with the system linker so Python can load them at runtime. If you installed to the system Python prefix or via PPA, skip this step.
# Only needed for custom prefix installations
echo '/usr/local/python3.13/lib' | sudo tee /etc/ld.so.conf.d/python3.13.conf
sudo ldconfig
sudo ln -sf /usr/local/python3.13/bin/python3.13 /usr/local/bin/python3.13
ldconfig reads all paths in /etc/ld.so.conf.d/, updates the dynamic linker cache, and enables the OS to find shared libraries (like libpython3.13.so) when you run Python. The symlink in /usr/local/bin adds convenience so python3.13 works from any directory without typing the full path.
Verify the build and confirm critical modules compiled successfully:
python3.13 --version
python3.13 -c "import ssl, sqlite3, bz2; print('Source build is healthy')"
Python 3.13.13 Source build is healthy
If the second command fails, reinstall missing -dev packages using the “Install Build Dependencies” section above, rerun ./configure, and rebuild with make -j"$(nproc)" and sudo make altinstall.
Update a Source-Built Python 3.13 Installation
Source-built Python does not receive automatic updates from APT. When a new 3.13.x patch release is available, you need to download the new source, recompile, and reinstall. The helper in this section automates that process while keeping your existing installation prefix at /usr/local/python3.13.
Prepare the Source Update Workspace
First, create a dedicated build directory under /usr/local/src to keep source trees and build artifacts organized alongside your installation prefix:
sudo install -d /usr/local/src/python3.13-build
Create the Python 3.13 Update Helper
Next, create a PATH-based update helper. This script performs several safety checks before rebuilding:
- Root check: Verifies you are running as root since compilation installs to system directories.
- Tool check: Confirms curl is available for the version check, then confirms tar, gcc, make, and gpg only before a rebuild.
- Keyring check: Verifies the Python release GPG keyring exists before downloading and verifying a newer source tarball.
- Existing install check: Confirms a prior source build exists before attempting an upgrade.
- Version detection: Compares the installed source build with the latest 3.13.x version number from python.org.
cat <<'EOF' | sudo tee /usr/local/bin/update-python313
#!/usr/bin/env bash
set -euo pipefail
# Verify running as root
if [ "$(id -u)" -ne 0 ]; then
echo "Run as root: sudo update-python313"
exit 1
fi
# Check curl before version detection
if ! command -v curl >/dev/null 2>&1; then
echo "Error: curl is required. Install curl first."
exit 1
fi
# Verify existing source installation
PREFIX="/usr/local/python3.13"
if [ ! -x "$PREFIX/bin/python3.13" ]; then
echo "Error: $PREFIX/bin/python3.13 not found. Install Python 3.13 from source first."
exit 1
fi
CURRENT="$("$PREFIX/bin/python3.13" -c 'import platform; print(platform.python_version())')"
echo "Installed Python $CURRENT"
# Detect latest 3.13.x version
echo "Checking for latest Python 3.13.x release..."
LATEST="$(curl -fsSL https://www.python.org/ftp/python/ | grep -oE '3\.13\.[0-9]+' | sort -V | tail -1)"
if [ -z "$LATEST" ]; then
echo "Error: Could not determine the latest 3.13.x version."
exit 1
fi
echo "Found Python $LATEST"
if [ "$CURRENT" = "$LATEST" ]; then
echo "Python 3.13 is already current ($CURRENT)."
exit 0
fi
printf "Update source-built Python 3.13 from %s to %s? [y/N] " "$CURRENT" "$LATEST"
read -r answer
case "$answer" in
[Yy]|[Yy][Ee][Ss]) ;;
*) echo "Update cancelled."; exit 0 ;;
esac
# Check build tools only when a rebuild is needed
for cmd in tar gcc make gpg; do
if ! command -v "$cmd" >/dev/null 2>&1; then
echo "Error: $cmd is required for rebuilds. Install build-essential, tar, and gpg."
exit 1
fi
done
# Verify GPG keyring exists before source verification
KEYRING="/usr/share/keyrings/python-release.gpg"
if [ ! -f "$KEYRING" ]; then
echo "Error: $KEYRING not found. Import Python release keys first."
exit 1
fi
# Download and verify source
WORKDIR="/usr/local/src/python3.13-build"
cd "$WORKDIR"
rm -rf "Python-${LATEST}"
rm -f "Python-${LATEST}.tar.xz" "Python-${LATEST}.tar.xz.asc"
echo "Downloading Python-${LATEST}.tar.xz..."
curl -fsSLO "https://www.python.org/ftp/python/${LATEST}/Python-${LATEST}.tar.xz"
curl -fsSLO "https://www.python.org/ftp/python/${LATEST}/Python-${LATEST}.tar.xz.asc"
echo "Verifying GPG signature..."
gpg --no-default-keyring --keyring "$KEYRING" --verify "Python-${LATEST}.tar.xz.asc" "Python-${LATEST}.tar.xz"
echo "SHA-256 checksum:"
sha256sum "Python-${LATEST}.tar.xz"
# Extract and compile
echo "Extracting source..."
tar -xf "Python-${LATEST}.tar.xz"
cd "Python-${LATEST}"
echo "Configuring build (this takes a few minutes)..."
./configure --with-ensurepip=install --prefix="$PREFIX"
echo "Compiling (this may take 10-30 minutes depending on CPU)..."
make -j"$(nproc)"
echo "Installing..."
make altinstall
# Verify
echo ""
echo "Update complete:"
"$PREFIX/bin/python3.13" --version
EOF
sudo chmod +x /usr/local/bin/update-python313
The helper checks the installed version before touching the build directory. If your source build already matches the latest Python.org 3.13.x release, it exits without checking compiler tools, downloading source files, or reinstalling Python.
Run the Python 3.13 Update Helper
Execute the helper manually whenever you want to update to the latest 3.13.x patch release:
sudo update-python313
Installed Python 3.13.x Checking for latest Python 3.13.x release... Found Python 3.13.x Python 3.13 is already current (3.13.x).
Avoid automating this with cron. Compilation can fail due to missing dependencies, build failures, or network issues. When the helper finds a newer patch version, it prompts before downloading, verifying, rebuilding, and installing into the same prefix. Run it manually and review the output before using the updated interpreter in projects.
Compare Python Versions on Ubuntu (Reference)
Ubuntu LTS releases ship different default Python versions, and Canonical patches those defaults for the life of the release. Use this comparison table when deciding whether Python 3.13 is the right target for your project or whether another version is a better fit.
| Python Version | Availability on Ubuntu | Choose It When | Trade-offs |
|---|---|---|---|
| Install Python 3.8 on Ubuntu | Deadsnakes PPA or source build only | Legacy applications pinned to 3.8-only dependencies or short-term migration windows | Upstream end-of-life October 2024; security patches ended; ecosystem support declining |
| Install Python 3.10 on Ubuntu | Ubuntu 22.04 LTS default | Production environments prioritizing stability on 22.04 LTS (supported through June 2027) | Upstream Python 3.10 EOL October 2026; Ubuntu continues patching until 22.04 LTS ends |
| Install Python 3.11 on Ubuntu | Deadsnakes PPA or source build | Projects needing 3.11 features without jumping to 3.12 or 3.13 | Not a system default on current Ubuntu LTS releases; upstream EOL October 2027 |
| Install Python 3.12 on Ubuntu | Ubuntu 24.04 LTS default; Deadsnakes PPA or source build on other releases | General-purpose development on 24.04 LTS (supported through June 2029) | Upstream Python 3.12 EOL October 2028; Ubuntu continues patching its default branch until 24.04 LTS ends |
| Python 3.13 | Deadsnakes PPA for Ubuntu 26.04/24.04/22.04; source builds for custom needs | Teams testing the free-threaded CPython preview, projects adopting 3.13 features, forward-looking development targeting upstream support through October 2029 | Community packages lack Canonical security SLAs; some third-party wheels may lag; not the system default on current Ubuntu LTS releases |
| Install Python 3.14 on Ubuntu | Ubuntu 26.04 LTS default; Deadsnakes PPA or source builds for 24.04/22.04 | 26.04 users staying with the release default, or older-release users planning for the longer upstream support window | Best system-owned choice on 26.04; older releases still need community packages or source builds |
Recommendation for Choosing Python 3.13 on Ubuntu
Stick with the Ubuntu default Python for your release when you prefer Canonical-managed security updates. Use Python 3.13 on development workstations, CI runners, or isolated services that need the free-threaded preview or newer 3.13 features, and plan to move to Python 3.14 when you want the longer security runway. Avoid replacing the system Python that ships with Ubuntu.
Install Pip for Python 3.13 on Ubuntu
Ubuntu and Deadsnakes packages do not install pip by default, so verify it before installing third-party packages.
Install Pip with python3.13-venv
Use a Python 3.13 virtual environment so pip installs stay isolated from Ubuntu’s package-managed Python. If you compiled from source with --with-ensurepip=install, you can skip the APT venv package and create the environment from your source-built interpreter.
sudo apt install python3.13-venv -y
python3.13 -m venv ~/venvs/py313-base
source ~/venvs/py313-base/bin/activate
pip --version
pip 25.x from /home/ubuntu/venvs/py313-base/lib/python3.13/site-packages/pip (python 3.13)
The pip version and path vary by release and venv location. This example uses Ubuntu 26.04 with a venv created under
~/venvs/py313-base.
If python3.13 -m venv reports that ensurepip is unavailable, install the matching python3.13-venv package and recreate the environment. Do not run ensurepip with sudo against Ubuntu’s system interpreter.
For Deadsnakes PPA installs, prefer
python3.13-venvand project venvs over global pip. For source builds with a custom prefix, the pip path reflects that prefix; usepython3.13 -m pip --versioninside the active venv to confirm the install location.
Bootstrap Pip with get-pip.py
For air-gapped hosts or custom source builds, download the bootstrap script and review it before running with Python 3.13. Prefer virtual environments and only fall back to get-pip.py when the venv package or source-build ensurepip path is blocked.
curl -fsSLo get-pip.py https://bootstrap.pypa.io/get-pip.py
python3.13 get-pip.py
rm get-pip.py
This installs pip, setuptools, and wheel together. Always fetch a fresh copy of get-pip.py before rerunning the installer.
Manage Packages with python3.13 -m pip
Run these commands inside your active Python 3.13 virtual environment:
python3.13 -m pip install package_name
python3.13 -m pip install --upgrade package_name
python3.13 -m pip uninstall package_name
Replace package_name with libraries like numpy, fastapi, or django. For detailed pip workflows, see Install Python pip on Ubuntu.
After installing dependencies, verify compatibility and check for conflicts:
python3.13 -m pip check
No broken requirements found.
This command reports broken dependencies, version conflicts, and missing packages that your installed libraries require. If issues are detected, pip lists them so you can fix conflicts before committing code that depends on those packages.
Install Python Packages and Verify Compatibility
After pip is working, install packages relevant to your workflow and test compatibility with pip check. Dependency support still varies by project, especially for native extensions and free-threaded builds, so test critical packages before deploying.
Test FastAPI with Python 3.13
Example: Install FastAPI and verify compatibility
python3.13 -m pip install fastapi uvicorn
python3.13 -m pip check
If pip check returns no conflicts, FastAPI is ready for Python 3.13. If warnings appear, review the output and consider using a venv to isolate the installation.
Test Django with Python 3.13
Example: Install Django and run compatibility tests
python3.13 -m pip install django psycopg2-binary
python3.13 -m pip check
If psycopg2-binary installation fails with a compiler error, the package requires build tools. Install the necessary headers: sudo apt install python3.13-dev, then retry.
Handle Python 3.13 Data Science Wheel Lag and PEP 668
Data science wheel availability: NumPy, Pandas, and scikit-learn may lag behind new Python releases. If installation fails, check the package’s GitHub releases or PyPI package page for 3.13 wheel support. Avoid --break-system-packages; use virtual environments for all work.
Ubuntu 26.04 and 24.04 mark the system Python as externally managed under PEP 668, so pip refuses to write to package-managed paths without a virtual environment. Deadsnakes PPA builds and source builds install separately, but you should still use venvs to isolate projects.
Install packages inside a virtual environment instead of bypassing protections. If you compiled Python 3.13 from source, pip installs to its prefix without PEP 668 prompts, but venvs still prevent cross-project conflicts.
Use virtual environments for all project work. Avoid
--break-system-packages; it is only suitable for disposable environments, not daily development or production machines.
Work in Python 3.13 Virtual Environments
Virtual environments isolate dependencies per project. Each environment gets its own interpreter copy and package directory, preventing version conflicts between projects. For expanded guidance, visit Create Python Virtual Environments on Ubuntu.
Create a Python 3.13 Virtual Environment
Choose a directory for your environments (for example ~/venvs) and create one with Python 3.13:
python3.13 -m venv ~/venvs/py313
Swap ~/venvs/py313 for any path that matches your workflow.
Activate the Python 3.13 Virtual Environment
Activate the environment so python and pip resolve to the local interpreter:
source ~/venvs/py313/bin/activate
The shell prompt updates with the environment name, indicating activation.
Deactivate the Python 3.13 Virtual Environment
When finished, run:
deactivate
This returns your shell to the system Python context.
Troubleshooting Common Python 3.13 Installation Issues
Missing Python 3.13 Development Headers During Compilation
If ./configure completes but reports disabled modules for SSL, bz2, sqlite, readline, or other standard library features, critical development headers are missing. Identify which modules were disabled and install the corresponding packages.
Review the configure output to identify disabled modules:
./configure --with-ensurepip=install --prefix=/usr/local/python3.13 2>&1 | grep "disabled\|WARNING"
You may also see a warning about bundled libmpdec during ./configure on Ubuntu. This warning does not prevent a successful Python 3.13 build as long as required modules are not listed as disabled.
Common missing packages and the modules they enable:
- SSL module disabled -> Install
sudo apt install libssl-dev - sqlite3 module disabled -> Install
sudo apt install libsqlite3-dev - bz2 module disabled -> Install
sudo apt install libbz2-dev - readline module disabled -> Install
sudo apt install libreadline-dev - dbm module disabled -> Install
sudo apt install libgdbm-dev
After installing the missing packages, rerun ./configure and make -j"$(nproc)" to rebuild with full module support.
Python 3.13 Shared Library Linking Errors
If running python3.13 returns error while loading shared libraries: libpython3.13.so.1.0: cannot open shared object file, the linker cannot find the Python library. This occurs when you installed to a custom prefix and forgot to register it with ldconfig.
Locate the library:
find /usr/local -name "libpython3.13.so*"
If the library exists, register its directory and refresh the cache:
echo "/usr/local/python3.13/lib" | sudo tee /etc/ld.so.conf.d/python3.13.conf
sudo ldconfig
Verify the library loads:
python3.13 --version
If the library does not exist, the compilation likely failed. Rerun ./configure, make -j"$(nproc)", and sudo make altinstall in the source directory, then try the ldconfig steps again.
Resolve Externally Managed Environment Errors
On Ubuntu 24.04 LTS and 26.04 LTS, the system Python is externally managed under PEP 668, so pip blocks direct installs to /usr without a virtual environment. The error looks like this:
error: externally-managed-environment This environment is externally managed. To install Python packages system-wide, try apt install python3-xyz, where xyz is the package you are trying to install. If you wish to install a non-Debian-packaged Python package, create a virtual environment using python3 -m venv path/to/venv. Then use path/to/venv/bin/python and path/to/venv/bin/pip. Make sure you have python3-full installed. If you wish to install a non-Debian packaged Python application, it may be easiest to use pipx install xyz, which will manage a virtual environment for you. Make sure you have pipx installed. See /usr/share/doc/python3.x/README.venv for more information. note: If you believe this is a mistake, please contact your Python installation or OS distribution provider. You can override this, at the risk of breaking your Python installation or OS, by passing --break-system-packages. hint: See PEP 668 for the detailed specification.
Your output may wrap lines differently, but the fix is the same: use a virtual environment.
Create a venv instead of bypassing protections:
python3 -m venv myproject_env
source myproject_env/bin/activate
pip install package-name
Swap python3 with python3.13 if you want the Python 3.13 interpreter inside the venv. Skip --break-system-packages on any host you care about. Virtual environments isolate dependencies cleanly without risking apt-managed files.
Python 3.13 PPA Candidate Missing or System Python Changed
If apt-cache policy python3.13 shows no candidate, the Deadsnakes PPA is not enabled for your current codename or APT metadata is stale. Recheck the PPA section, run sudo apt update, and confirm the repository line matches your release (resolute, noble, or jammy).
If Python commands or APT tools break after installing Python 3.13, verify that Ubuntu’s default python3 symlink still points to the release-owned interpreter:
python3 --version
readlink -f /usr/bin/python3
dpkg -S /usr/bin/python3
Example output on Ubuntu 26.04 looks like this:
Python 3.14.x /usr/bin/python3.14 python3-minimal: /usr/bin/python3
On Ubuntu 24.04, the version line should show Python 3.12.x and readlink should resolve to /usr/bin/python3.12. On Ubuntu 22.04, it should show Python 3.10.x and resolve to /usr/bin/python3.10. Ubuntu 26.04 resolves to Python 3.14.x.
If /usr/bin/python3 was manually relinked, do not keep editing symlinks. Reinstall the package-owned default instead, then call Python 3.13 explicitly with python3.13:
sudo apt install --reinstall python3-minimal
GPG Key Import Failures for Source Builds
If verifying the Python source tarball fails with “No public key” or “Can’t check signature” errors, the release signing key may not have imported correctly. First, confirm the keyring file exists:
ls -la /usr/share/keyrings/python-release.gpg
If missing, re-import the key:
curl -fsSL https://keys.openpgp.org/vks/v1/by-fingerprint/7169605F62C751356D054A26A821E680E5FA6305 | sudo gpg --dearmor --batch --yes -o /usr/share/keyrings/python-release.gpg
If the key server is unreachable (network restrictions or temporary outage), you can skip GPG verification and rely solely on SHA-256 checksum verification. Compare the checksum output from sha256sum Python-*.tar.xz with the hash on the Python.org downloads page. GPG verification adds an extra layer of assurance but is not strictly required if the checksum matches.
C Extension Build Failures During pip install
Some Python packages like psycopg2, cryptography, and numpy require compilation (C extensions). If pip install package-name fails with compiler errors, you need Python development headers. Install them:
sudo apt install python3.13-dev
For Deadsnakes PPA: The package is called python3.13-dev. For source builds: Development headers were built during compilation and live in /usr/local/python3.13/include/python3.13.
After installing headers, retry the package installation:
python3.13 -m pip install psycopg2-binary # or the package that failed
If compilation still fails, the package may not have released Python 3.13 wheels yet. Check the package’s PyPI package page or GitHub releases to confirm support before reporting a bug.
Fix “ensurepip is not available” When Creating a Python 3.13 venv
If python3.13 -m venv fails with an ensurepip is not available message, the interpreter is installed but the venv support package is missing. This is common when the Deadsnakes interpreter was installed without python3.13-venv.
The virtual environment was not created successfully because ensurepip is not available. On Debian/Ubuntu systems, you need to install the python3.13-venv package...
Install the venv package, recreate the environment, and verify pip inside the venv:
sudo apt install python3.13-venv
python3.13 -m venv ~/venvs/py313-test
~/venvs/py313-test/bin/pip --version
For source builds, rerun ./configure with --with-ensurepip=install from the source-build section, then rebuild and reinstall with sudo make altinstall. If you intentionally skipped ensurepip, use the get-pip.py fallback method shown earlier.
Switch Back to Ubuntu’s System Python
If Python 3.13 introduces compatibility issues with critical packages or projects, you can safely revert to the system Python without affecting the interpreter Ubuntu ships. Virtual environments isolate project dependencies, so switching back affects only new projects.
Use the system interpreter directly for new environments. Ubuntu 26.04 LTS uses Python 3.14 as the system interpreter, Ubuntu 24.04 LTS uses Python 3.12, and Ubuntu 22.04 LTS uses Python 3.10.
Rebuild Existing Virtual Environments with the System Python
Virtual environments created with Python 3.13 are tied to that interpreter. To switch a project back to your system Python, remove the old venv and create a new one with your release’s default interpreter.
# Remove the Python 3.13 venv
rm -rf ~/venvs/py313
# Create a new venv with the system Python
# Ubuntu 26.04 LTS
python3.14 -m venv ~/venvs/py314
# Ubuntu 24.04 LTS
python3.12 -m venv ~/venvs/py312
# Ubuntu 22.04 LTS
python3.10 -m venv ~/venvs/py310
source ~/venvs/py314/bin/activate # or ~/venvs/py312 / ~/venvs/py310
pip install -r requirements.txt # If using a requirements file
Virtual environments are isolated, so old ones with Python 3.13 remain on disk until you delete them. Once deleted, you cannot use them. Keep backups of requirements.txt or Pipfile to rebuild environments quickly.
Update or Remove Python 3.13 on Ubuntu
APT-installed Python 3.13 and source-built Python 3.13 use different maintenance paths. Use APT for Deadsnakes PPA packages, and use the update-python313 helper from the source-build section when you compiled into /usr/local/python3.13.
Update Python 3.13 Packages
sudo apt update
sudo apt install --only-upgrade python3.13 python3.13-venv python3.13-dev python3.13-full
The --only-upgrade flag updates Python 3.13 packages only if they are already installed; it will not install Python 3.13 if it is missing. This prevents accidental installation while ensuring existing packages receive updates from the Deadsnakes PPA.
Remove Python 3.13 Packages from the Deadsnakes PPA
These commands target versioned Deadsnakes Python 3.13 packages. Do not remove Ubuntu’s unversioned
python3,python3-minimal, or release-default interpreter packages.
Uninstall Python 3.13 from the PPA if you no longer need it (this also removes the optional add-on packages if installed):
sudo apt remove --purge python3.13 python3.13-venv python3.13-dev python3.13-full python3.13-dbg python3.13-gdbm python3.13-tk
Preview any orphaned dependency cleanup before removing additional packages:
sudo apt autoremove --dry-run
If the preview only lists packages you no longer need, run the cleanup interactively:
sudo apt autoremove
Remove the Deadsnakes PPA
Clean up the PPA and APT pinning configuration only if you no longer use any Deadsnakes packages. If you installed other Python branches from the same PPA, leave the repository enabled and remove only the Python 3.13 packages above.
sudo rm -f /etc/apt/preferences.d/python313-deadsnakes-pin
sudo add-apt-repository --remove ppa:deadsnakes/ppa -y
sudo rm -f /etc/apt/trusted.gpg.d/deadsnakes-ubuntu-ppa.gpg /etc/apt/trusted.gpg.d/deadsnakes-ubuntu-ppa.gpg~
sudo apt update
If you only installed Python 3.13 from the Deadsnakes PPA (and did not also install a source build), verify the package and PPA are gone:
dpkg-query -W -f='${db:Status-Abbrev} ${binary:Package}\n' 'python3.13*' 2>/dev/null | grep '^ii' || echo "No installed Python 3.13 packages found"
apt-cache policy python3.13
No installed Python 3.13 packages found python3.13: Installed: (none) Candidate: (none) Version table:
If the output still shows a Deadsnakes candidate version, the PPA was not fully removed. Rerun the add-apt-repository --remove command and sudo apt update.
Clean Up Source-Compiled Python 3.13 Installations
Remove source installs and related linker entries if you compiled Python 3.13 manually:
The next commands permanently delete the source-built Python 3.13 tree at
/usr/local/python3.13, the source workspaces, and the update helper. Back up any custom modules first withsudo cp -a /usr/local/python3.13 ~/python3.13-backup.
sudo rm -rf /usr/local/python3.13
sudo rm -rf /usr/local/src/python3.13-build
rm -rf "$HOME/src/python3.13-build"
sudo rm -f /etc/ld.so.conf.d/python3.13.conf
sudo rm -f /usr/local/bin/python3.13
sudo rm -f /usr/local/bin/python3.13t
sudo rm -f /usr/local/bin/update-python313
sudo ldconfig
Adjust the path if you used a custom prefix such as /opt/python3.13.
Verify the source-build files were removed:
remaining=0
for path in /usr/local/python3.13 /usr/local/src/python3.13-build "$HOME/src/python3.13-build" /etc/ld.so.conf.d/python3.13.conf /usr/local/bin/python3.13 /usr/local/bin/python3.13t /usr/local/bin/update-python313; do
if [ -e "$path" ]; then
echo "Still present: $path"
remaining=1
fi
done
if [ "$remaining" -eq 0 ]; then
echo "Source-build files removed"
fi
Source-build files removed
Next Steps After Installing Python 3.13 on Ubuntu
Use these follow-up tasks to move from installation to day-to-day development without changing Ubuntu’s system Python.
- Create a project venv: Run
python3.13 -m venv ~/myproject, then activate it withsource ~/myproject/bin/activate. - Install project dependencies: Inside the active venv, use
python -m pip install django,python -m pip install fastapi, or your required packages, then runpython -m pip check. - Set up a lightweight IDE: If you want Python’s bundled editor for testing and learning, install IDLE on Ubuntu.
- Plan upgrades: Track Python 3.13 security updates and install Python 3.14 on Ubuntu when you need the longer support window, well before Python 3.13 reaches upstream end-of-life in October 2029.
- Validate production readiness: Benchmark your real workload, especially if you are evaluating the optional free-threaded build, before moving production services.
Useful Python 3.13 Resources for Ubuntu
Keep these references handy for release notes, security updates, and package availability checks.
- Python Official Website: Download releases and review project updates.
- Python Documentation: Read the language and standard library docs.
- What’s New in Python 3.13: Review new features, deprecations, and behavior changes.
- PEP 719: Python 3.13 Release Schedule: Confirm the support timeline through October 2029.
- PEP 703: Optional GIL in CPython: Understand free-threaded background and current limitations.
- Deadsnakes PPA on Launchpad: Check supported Ubuntu releases and package publishing status.
Conclusion
Python 3.13 is running alongside Ubuntu’s default interpreter, with pip working inside a virtual environment and the versioned python3.13 binary available system-wide. Keep dependencies isolated in venvs, track upstream security advisories through October 2029, and use Python 3.14 on Ubuntu when you want the newer default on 26.04 or the longer upstream support window. For expanded pip workflows, see install pip on Ubuntu.


Formatting tips for your comment
You can use basic HTML to format your comment. Useful tags currently allowed in published comments:
<code>command</code>command<strong>bold</strong><em>italic</em><blockquote>quote</blockquote>