50

I tried apt install python 3.9 and it replied:

Reading package lists... Done Building dependency tree Reading state information... Done E: Unable to locate package python3.9 E: Couldn't find any package by glob 'python3.9' E: Couldn't find any package by regex 'python3.9' 
2
  • 2
    You can install Python 3.9 Alpha 5 from the Deadsnakes PPA. But be aware: it is an Alpha version. It can and will contain bugs and might be incompatible with many known packages. Commented Mar 24, 2020 at 4:05
  • I know this is an old question but for old ubuntu version the only way I found is the one related by @Akash Kumar https://stackoverflow.com/a/64353748/9794948 Commented Jan 4, 2024 at 6:19

3 Answers 3

84

If you are on Ubuntu 19.10 (Eoan Ermine) (or any other version unsupported by the deadsnakes PPA), you will not be able to install using the deadsnakes PPA.

What you can do instead, is get the source from Python's official website, and install it manually, as described here.

To do so, first, install the dependencies required to build the Python package.

sudo apt install build-essential zlib1g-dev \ libncurses5-dev libgdbm-dev libnss3-dev \ libssl-dev libreadline-dev libffi-dev curl software-properties-common 

Then download the tarball and extract it:

wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tar.xz tar -xf Python-3.9.0.tar.xz 

Then cd to the extracted directory:

cd Python-3.9.0 

Now configure the script:

./configure 

Now, to install Python 3.9 alongside your current Python installation (if any), use:

sudo make altinstall 

Lastly, you can verify your installation using

python3.9 --version 

How to make python3.X default of Python 3? (Optional)

rm /usr/bin/python3 ln -s /usr/bin/python3.5 /usr/bin/python3 
  • create an alias in ~/.bash_aliases, ~/.zshrc, etc.
alias python3='/usr/bin/python3.9' 

or

alias python3='/usr/local/bin/python3.9' 
Sign up to request clarification or add additional context in comments.

5 Comments

How to make it a default version for python3 ?
@raaj python3 is symbolic link to some version of python, so you can 1) sudo unlink /usr/bin/python3 2) sudo ln -s /usr/bin/python3.9 /usr/bin/python3
This helped me a lot but then I found that I can't import tkinter. The solution was to brute-force uninstall python3.9, sudo apt install tk-dev tcl-dev and then reinstall python3.9 as explained above. So, I suggest for anybody to add tk-dev tcl-dev to the list of packages to be installed in the first command of this answer.
Update. It also turned out that sqlite3 is not installed. Therefore, I believe the list of what should be installed BEFORE configuring and installing python from source should be: sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev curl software-properties-common tk-dev tcl-dev libsqlite3-dev
Thank you! Finally found a way to install Python 3.9 on Ubuntu 18.04!
41

You are getting that error because you first need to update the package list and the prerequisites.

sudo apt update sudo apt install software-properties-common 

Then, add the repository ppa:deadsnakes/ppa to your sources list (where you will download Python from)

sudo add-apt-repository ppa:deadsnakes/ppa 

Make sure to press Enter when prompted. Then update available the packages:

sudo apt update 

Lastly, install the version of your choice:

sudo apt install python3.9 

Make sure to read this:

Disclaimer: there's no guarantee of timely updates in case of security problems or other issues. If you want to use them in a security-or-otherwise-critical environment (say, on a production server), you do so at your own risk.

PPA Deadsnake

2 Comments

run sudo apt update before sudo apt install python3.9, or it still will not locate the package
Tried this, didn't help, couldn't install it. I have Ubuntu 22.04.1 LTS.
1

I have spent a long time searching for this but found the answer here first: https://github.com/baralraj/python-3.9-on-wsl/blob/main/README.md

1st: Update and install some required packages that are needed to build python from source.

sudo apt update sudo apt upgrade sudo apt install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev wget 

2nd: Create a temp directory, download the python source code and unzip (I usually just download it manually from that url in the browser and unzip it with the files UI)

mkdir ~/tmp cd ~/tmp wget https://www.python.org/ftp/python/3.9.12/Python-3.9.12.tgz tar -xvzf Python-3.9.12.tgz 

3rd: Configure and install

cd Python-3.9.12 ./configure sudo make altinstall 

4th: check the installation

python3.9 --version 

Output should be

Python 3.9.12

Comments

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.