27

I need to install an older version of Python to get some software to work. 3.9 is the newest version I can use.

Someone else had this issue and the answer was:

sudo add-apt-repository universe
sudo apt update
sudo apt install python3.9

However this does not work and just gives an error that the 3.9 package can not be found.

So how can I remove 3.10 and get 3.9 instead? Thanks.

fletch
  • 371

3 Answers3

30

I encourage to install just your python dependencies using a python package, as this other question and answer suggest: How do I install a different Python version using apt-get?

sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt-get update
sudo apt-get install python3.9
cserpell
  • 440
7

Install anaconda https://phoenixnap.com/kb/how-to-install-anaconda-ubuntu-18-04-or-20-04

Anaconda manages different versions of python and their packages by creating environments that are isolated.

So you can install whatever versions of python without crushing.

conda create --name envp39 python=3.9 

This creates python environment with python 3.9

You can switch version by changing environments with

conda activate envp39

You have to open/install the software in a shell with activated envp39.

Tom
  • 725
3

I think the most pythonic way would be to create a virtual environment and then run your script in the env. For example, if you have miniconda/Anaconda installed,

$ conda create -n your_env_name python=3.9
$ conda activate your_env_name

Install all packages you need:

(your_env_name) $ conda install package_name

If the package is not in conda,

(your_env_name) $ cd ~/your_conda_directory/envs/your_env_name/bin
(your_env_name) $ pip install package_name

Make sure you verify Python version

(your_env_name) $ python --version
Python 3.9.12

And now you are good to go:

(your_env_name) $ python your_code.py

Good luck!