You want to install a specific Python version, e.g., Python 3.9, on Ubuntu 23.10; neither Ubuntu PPA nor Deadsnakes PPA distributes it. Fortune has it; you don’t have to compile CPython from the source manually. And you don’t have to change your Ubuntu to an LTS version, e.g., 23.04 or 24.04, where Deadsnakes PPA supports your version.
You have these options:
- pyenv (Simple Python Version Management)
- conda (Anaconda or Miniconda)
- asdf (tool version manager)
- Docker (containerized Python possible but complex)
Pyenv
pyenv lets you easily switch between multiple versions of Python. Each version is compiled on your machine for you and for most popular versions the compilation should work reliably.
- Follow installation process here.
- Then you can run
pyenv install 3.9
and it should compile it from source.
Conda
Conda instead provides precompiled version of Python for different platforms. Although the support may not be guaranteed and a compilation fallback is an option. In contrast to pyenv, conda is an environment manager and a package manager, so you can create multiple separate environments and install different precompiled packages into them.
- Install conda from here.
- Then you can create an environment:
conda create -n my-python-3.9-environment python=3.9
- Then you need to activate the environment:
conda activate my-python-3.9-environment
asdf
Appears to be popular, but I have no experience with it. Here is an example.
asdf install python 3.7.4
Docker
This is the least practical but the most flexible and reliable approach. Dokcer is usually only used to run single version applications. Docker is not intended as a development environment. But there is a support for IDE’s like Pycharm to run a Python interpreter in Docker containers.
I hope this helps
This is a webpage I wanted to find, when a college was having this problem. I hope it helps you now.