So finally I found out how to install Python 3.10 from sources
dependencies needed for building:
sudo apt install -y build-essential libssl-dev libbz2-dev libreadline-dev libsqlite3-dev wget curl llvm libffi-dev zlib1g-dev
Download and extract the sources
cd /opt
sudo wget https://www.python.org/ftp/python/3.10.12/Python-3.10.12.tgz
sudo tar -xvf Python-3.10.12.tgz
Compile and Install
cd Python-3.10.12
sudo ./configure --enable-optimizations
sudo make altinstall
Answer from Vincent Tschanz on askubuntu.comCorrect way to install Python 3.12 on Ubuntu 24.04 (with pip & venv)?
Install python 3.11.9 on ubuntu
How can I completely remove and re-install python3.10 that is located in ~/.local ? (Ubuntu 22.04)
need to install python3.10
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.