Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
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
@gbonline

This comment has been minimized.

Copy link

@gbonline gbonline commented Sep 13, 2018

Hi, I've followed these instructions on ubuntu 18.04 desktop, but configuring python 3.7 as default for pyton3 causes the impossibility to open the terminal, What i have to do to call it as python37?

@ulrichmabou

This comment has been minimized.

Copy link

@ulrichmabou ulrichmabou commented Sep 26, 2018

Hi, I've followed these instructions on ubuntu 18.04 desktop, but configuring python 3.7 as default for pyton3 causes the impossibility to open the terminal, What i have to do to call it as python37?


Hi @gbonline, I have the same problem. Installed Python 3.7 on Ubuntu 18.04 this morning and configured it as default for python3 as described above. Few hours later, I realized that I couldn't use the terminal anymore and there is an error message at the top-right corner ('A problem occured when checking for updates').

Using the XTerm terminal (got assistance from a friend), we also got an error like this:

E: Problem executing scripts APT::Update::Post-Invoke-Success 'if /usr/bin/test -w ......... > /dev/null; fi'
E: Sub-process returned an error code


Did you manage to resolve your issue?

@vmm86

This comment has been minimized.

Copy link

@vmm86 vmm86 commented Oct 12, 2018

pip list command may be broken after the Python 3.7 installation on Ubuntu 18.04 due to mistake in lsbrelease module.
If you've faced such mistake you should change the first shebang line of /usr/bin/lsb_release to #!/usr/bin/python2.7 to force execution with Python 2.7. You should also edit line 64 to print("No LSB modules are available.", sys.stderr) to avoid print function exception in case it arises.

@rdonkin

This comment has been minimized.

Copy link

@rdonkin rdonkin commented Sep 18, 2019

If you don't need to build from source, a much simpler option is to do sudo apt-get install python3.7 (no extra repo required) then run python3.7 or use symlinks / shebang lines to point to this executable. This is quite safe - Ubuntu is OK with multiple versions as long as you don't change or symlink to alter meaning of existing executables.

The update-alternatives above is probably what breaks the system tools, as you are changing the version of Python used by tools - better to omit those commands and use a shebang line on your scripts, or symlinks under /usr/local/bin, to point to your new python3.7 binary with your preferred filename.

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