Skip to content

Instantly share code, notes, and snippets.

Show Gist options
  • Save alimp5/5d7b2a34ecb9a241f5e5ccc6bb84d8e8 to your computer and use it in GitHub Desktop.
Save alimp5/5d7b2a34ecb9a241f5e5ccc6bb84d8e8 to your computer and use it in GitHub Desktop.
Installing Python 3.7 from source on Ubuntu 18.04

Installing Python 3.7 from source on Ubuntu 18.04

# update system
sudo apt update && sudo apt upgrade -y

# install build tools and python prerequisites
sudo apt install build-essential libssl-dev zlib1g-dev libncurses5-dev libncursesw5-dev libreadline-dev libsqlite3-dev libgdbm-dev libdb5.3-dev libbz2-dev libexpat1-dev liblzma-dev tk-dev libffi-dev

# download and extract python
wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
tar xf Python-3.7.0.tar.xz
cd Python-3.7.0

# build python
./configure --enable-optimizations
# 'make -j <x>' enables parallel execution of <x> make recipes simultaneously
sudo make -j 8
# altinstall does not alter original system python install
sudo make altinstall

# run python3.7 when you type python3
sudo update-alternatives --install /usr/bin/python3 python3 /usr/local/bin/python3.7 1
sudo update-alternatives --install /usr/bin/python3 python3 /usr/bin/python3.6 2
# run below and select python3.7 from the list
sudo update-alternatives --config python3

# or create a shortcut
sudo ln -s /usr/local/bin/python3.7 /usr/bin/py
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment