Debian 9 – How to upgrade to python 3.9

This post relates specifically to python version 3.9.0. Although the generic commands should also apply to earlier versions, but your milage may vary.

The basic premise is, upgrade your version of python 3 to your desired version – 3.7.3 in this instance – then configure Debian to use python 3.9 at a higher priority to python 3.5.


Check your version
Step 1 is to check your current python version:

python3 -V

or

python3 --version

Download the latest or desired version of python 3
Next we need to download the latest version or desired version of python 3 from the python website. In my case I selected 3.7.3. Once downloaded we need to extract the tar file.

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

Make and Install
Now that we have the files downloaded and extracted, it is time to compile them.

./configure
make
make install

Switch to the new version
After compile the new version of python from source, we can now configure Debian to make it our default version of python3.

update-alternatives --install /usr/bin/python python /usr/local/bin/python3.9 10

The integer at the end of this command (10) sets the priority for the python version; the greater the integer, the higher the priority. At this point we can rerun the previously used version commands and we should see that we now have 3.9.0 active.


Fixing and Updating Pip
It was at this point that I attempted to install some required addons using pip and discovered that the upgrade to python 3.7.3 had broken a few things. These were the commands I used to resolved issues with lsb_release and pip:

ln -s /usr/share/pyshared/lsb_release.py /usr/local/lib/python3.9/site-packages/lsb_release.py

pip3 install --upgrade pip
  • python 3.7, upgrade python
  • 4 Users Found This Useful
Was this answer helpful?

Related Articles

How to Set Up a Mac for Your Kids

Providing children with access to a computer and the internet is increasingly important, but so...

How to Get Help With a Command from the Linux Terminal

Whether you’re an inexperienced terminal user or a grizzled veteran, you won’t always know the...

How to change the ssh port on Linux

To Change the SSH Port for Linux Server Connect to your server via SSH Switch to the root...

How To Install screenFetch in Linux

If you've browsed Linux groups on social media, you've probably seen a lot of screenshots that...

Static IP vs. Dynamic IP Address

A static IP address is one that remains fixed and never changes. The PC always sees the same...

Powered by WHMCompleteSolution