Skip to content

Instantly share code, notes, and snippets.

@FrancoMuniz
Forked from Sunlighter/README.md
Created May 13, 2021 07:58
Show Gist options
  • Save FrancoMuniz/fecf1da48373d7d509fe803472f5f293 to your computer and use it in GitHub Desktop.
Save FrancoMuniz/fecf1da48373d7d509fe803472f5f293 to your computer and use it in GitHub Desktop.
Installing Python 3.7 in Amazon Linux 2

Installing Python 3.7 in Amazon Linux 2

This is a way to build Python 3.7 from source and temporarily install it in Amazon Linux 2 without overwriting the system Python and without interfering with the Python in amazon-linux-extras.

At the time of this writing, Amazon Linux 2 offers Python 2.7.14 and (through the extras) Python 3.6.2, but Python 3.7.0 was just released.

  1. Start Amazon Linux 2 and sign in. (I recommend a c5.large instance.)

  2. Get the source tarball.

wget https://www.python.org/ftp/python/3.7.0/Python-3.7.0.tar.xz
  1. Uncompress it.
tar -xJf Python-3.7.0.tar.xz
  1. Get Prerequisites.
sudo yum install gcc bzip2-devel ncurses-devel gdbm-devel xz-devel sqlite-devel openssl-devel tk-devel uuid-devel readline-devel zlib-devel libffi-devel
  1. Create a target directory.
mkdir python37
  1. Configure and Build. (This takes a while with --enable-optimizations; omit it if you're in a hurry.)
cd Python-3.7.0/
./configure --prefix=/home/ec2-user/python37 --enable-shared --enable-optimizations
make
make install
  1. Alter your .bash_profile by adding $HOME/python37/bin to your PATH and setting LD_LIBRARY_PATH to $HOME/python37/lib. Log out and log in again.

  2. Use python3 to use your new Python interpreter. Or, optionally, create virtual environments.

  3. When you are done, you can undo your changes to .bash_profile and delete the python37 and Python3.7.0 directories.

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