Skip to content

Instantly share code, notes, and snippets.

@simonw
Created March 28, 2020 19:45
Show Gist options
  • Select an option

  • Save simonw/7d391ec1fdddd730e0075d963da65f1f to your computer and use it in GitHub Desktop.

Select an option

Save simonw/7d391ec1fdddd730e0075d963da65f1f to your computer and use it in GitHub Desktop.
How to run Python 3.7 on Ubuntu 16.04

How to run Python 3.7 on Ubuntu 16.04

This is based on Method 2 in https://websiteforstudents.com/installing-the-latest-python-3-7-on-ubuntu-16-04-18-04/

First, you need to install Python 3.7 (you will currently have Python 3.5.2):

sudo apt update
sudo apt install software-properties-common
sudo add-apt-repository ppa:deadsnakes/ppa
sudo apt update
sudo apt install python3.7

You now have two different versions of Python 3!

$ python3 --version
# Outputs 3.5.2
$ python3.7 --version
# Outputs 3.7

So you need to use pipenv but tell it to use Python 3.7 instead.

In a brand new folder do this:

pipenv --python=python3.7 install jupyterlab

Now you should be able to continue using the regular commands in that folder, e.g.

pipenv install altair
pipennv install pandas
pipenv run jupyter lab
@notmmao

notmmao commented Dec 18, 2021

Copy link
Copy Markdown

good job

@mayeaux

mayeaux commented Apr 5, 2022

Copy link
Copy Markdown

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.7
E: Couldn't find any package by glob 'python3.7'
E: Couldn't find any package by regex 'python3.7'

@robinjmf

robinjmf commented Apr 8, 2022

Copy link
Copy Markdown

Doesn't work:

Building dependency tree       
Reading state information... Done
E: Unable to locate package python3.7
E: Couldn't find any package by glob 'python3.7'
E: Couldn't find any package by regex 'python3.7'```

@vitabaks

Copy link
Copy Markdown

+ 1

Unable to locate package python3.7

@mahgulmalik

Copy link
Copy Markdown

doesn't work.

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.7
E: Couldn't find any package by glob 'python3.7'
E: Couldn't find any package by regex 'python3.7'

@RanTalbott

Copy link
Copy Markdown

No longer available:

add-apt-repository ppa:deadsnakes/ppa

Cannot add PPA: 'ppa:~deadsnakes/ubuntu/ppa'.
ERROR: '~deadsnakes' user or team does not exist.

@edfabs

edfabs commented Jun 6, 2022

Copy link
Copy Markdown

doesn't work

Reading package lists... Done
Building dependency tree
Reading state information... Done
E: Unable to locate package python3.7
E: Couldn't find any package by glob 'python3.7'
E: Couldn't find any package by regex 'python3.7'

@aguydane

aguydane commented Jul 4, 2022

Copy link
Copy Markdown

@edfabs may be because deadsnakes no longer explicitly supports 16.04: https://launchpad.net/~deadsnakes/+archive/ubuntu/ppa

@ZakiOro

ZakiOro commented Aug 17, 2022

Copy link
Copy Markdown

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

wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
sudo tar xzf Python-3.7.4.tgz

cd Python-3.7.4

sudo ./configure
sudo make
sudo make install

@attilalearning

attilalearning commented Dec 31, 2022 •

Copy link
Copy Markdown

Nice one @ZakiOro Thank you very much for those steps! :) They work out of the box, no errors! :) and

$ python3 --version
Outputs 3.7.4

Lovely! :D

@pazhosch

Copy link
Copy Markdown

Worked with Orange Pi One and Python 3.7.7, thanks!
Initially I've tried to build the latest Python 3.12.1, but it failed to build due to the outdated openssl. As my app (to be migrated from Raspberry Pi) is made for 3.7, I chose to download that version, and it worked well.

The new version was installed into /usr/local/bin/python, so I've then run:

$ sudo update-alternatives --install /usr/bin/python python /usr/local/bin/python3
$ update-alternatives --config python

to link /usr/bin/python to it (should it break anything in this old Ubuntu, it'll be very easy to revert using the latter command).

After running configure, I've also added: "-march=native -mtune=native" to BASECFLAGS in the makefile. Not sure if it will help this old and slow SBC a bit, but as I do not plan to use this build on another machine, it won't hurt.

@tharinduishans

Copy link
Copy Markdown

Thank you so much @ZakiOro. It worked like a charm

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