Correct way to install Python 3.12 on Ubuntu 24.04 (with pip & venv)?
Trying to install python 3.12.1 or 3.13.0 - Stack Overflow
Python 3.12
How to install specific python version if installer is not provided anymore
How do I upgrade from Python 3.10 to Python 3.12 on Ubuntu?
Can I install Python 3.12 on Ubuntu 20.04?
How do I install the python3.12-venv package on Ubuntu?
Videos
What’s the right way to install Python 3.12 on Ubuntu 24.04, with pip and venv working out of the box?
I tried:
sudo apt install python3.12.3
But it didn’t include pip or venv, and I hit an “externally managed environment” error when using pip in a venv.
Should I be using:
sudo apt install python3-full
or:
sudo apt-get install python3 python3-dev instead?
Just looking for the cleanest, correct way to get a working Python dev setup on this version of Ubuntu — any clarification appreciated.
I discovered this issue after trying the steps described in this article, which claims support for 20.04 | 22.04 | 23.04.
TL;DR straight to the fix:
echo "deb https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ jammy main" | sudo tee /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-lunar.list
sudo apt update
sudo apt install python3.12
The journey to get there:
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.12
However, as mentioned in the comments above, there is no "lunar" release in their apt ppa, and the apt update command fails. To resolve this, change the contents of /etc/apt/sources.list.d/deadsnakes-ubuntu-ppa-lunar.list (installed by add-apt-repository) from:
deb https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ lunar main
# deb-src https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ lunar main
to
deb https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ jammy main
# deb-src https://ppa.launchpadcontent.net/deadsnakes/ppa/ubuntu/ jammy main
This tells apt to install packages for 22.04 ("jammy"), which seems to work just fine on 23.04 for this package.
Then you can just run apt update and apt install python3.12 successfully
Use a virtual environment to resolve your issue.
Updating Python in Ubuntu can cause compatibility issues with system components and applications. Ubuntu relies on specific Python versions for its internal processes, and updating Python could disrupt these dependencies.
Use a Python Version Manager: Consider using a Python version manager like Pyenv or asdf to manage multiple Python versions on your system. These tools allow you to install and switch between different Python versions easily, and you can create virtual environments with any installed Python version.
Let me know if any further information is needed.