Skip to content

Instantly share code, notes, and snippets.

@sajalshres
Created August 13, 2021 08:49
Show Gist options
  • Save sajalshres/723fb2fc055b714e8ec39b364ebbb632 to your computer and use it in GitHub Desktop.
Save sajalshres/723fb2fc055b714e8ec39b364ebbb632 to your computer and use it in GitHub Desktop.
Deadsnakes python 3.9 on Ubuntu 18.04 LTS

Deadsnakes python 3.9 on Ubuntu 18.04 LTS

The deadsnakes PPA make the latest stable versions of python available on Ubuntu 18.04 LTS (3.9 is already in the official apt repo for 20.04). I now find it preferable to installing from source.

The following was tested on a Ubuntu 18.04.5 LTS desktop with python 3.6.9 as the system python version ("python3").

The latest python available from deadsnakes as of July, 2021 is 3.9.6.

Installation Procedure

  1. First, add the deadsnakes PPA to apt:
$ sudo add-apt-repository ppa:deadsnakes/ppa
  1. Next, do the usual update and upgrade:
$ sudo apt update && sudo apt upgrade

(if the result looks good to you, go ahead and answer "y" to do the upgrade)

  1. Then install the basic python3.9 packages:
$ sudo apt install python3.9 python3.9-dev python3.9-venv

This will install the python3.9 binary to /usr/bin.

  1. Make sure the associated pip is installed for your user environment:
$ python3.9 -m ensurepip --default-pip --user
  1. Fire up python3.9 to verify the install:
$ python3.9
Python 3.9.6 (default, Jul  3 2021, 17:50:42) 
[GCC 7.5.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> quit()
  1. Finally, make sure you can create a virtual environment:
$ cd testing
$ python3.9 -m venv venv
$ source venv/bin/activate
(venv) $ python --version
Python 3.9.6
(venv) $

Developer Workflow

One of the key reasons this works for me is that I've been aggressive about individually virtualizing project environments with venv.

I've trained myself to never to use sudo to when doing a "pip install", because there lies the road to ruin.

Once I've gone through the steps above I first test pip by trying to upgrade it with the "--user" flag:

$ python3.9 -m pip install --upgrade pip --user

The next thing I do is install ipython. Just because.

$ pip install ipython --user

From that point forward I try to minimize the packages I add to my base user environment, and try to regularly generate a requirements.txt (pip freeze >requirements.txt) to keep track of things. Each of my development projects has their own virtual environment created with venv.

@arvind-subramanian
Copy link

@johnrhunt -> Were you able to resolve this issue? Seeing the same behaviour.

@aviralchharia
Copy link

Same, does not work as of today.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment