DEV Community

Chenglu
Chenglu

Posted on

Installing Python 3.7.4 from source

I keep installing the Python from source, for two reason:

  1. More flexibility to manage. Cause I decide where to install it, which python module to enable.
  2. Chose the latest version. Python comes from system package manager is sometimes a older version.

Download Python source code.

wget https://www.python.org/ftp/python/3.7.4/Python-3.7.4.tgz
mkdir ~/.python3
mv Python-3.7.4.tgz ~/.python3
cd ~/.python3
tar -zxvf Python-3.7.4.tgz

Install dependencies

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

Enable ssl module

vim ~/.python3/Python-3.7.4/Modules/Setup.dist

find keyword ssl and uncomment this lines:

# SSL=/usr/local/ssl
# _ssl _ssl.c \
#         -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#         -L$(SSL)/lib -lssl -lcrypto

Compile and install

./configure --prefix=/root/.python3/ --with-ensurepip
make
make install

Add bin to PATH

Now the python3 and pip binary are located at ~/.python3/bin, you can add the directory to $PATH to access those commands directly.

Top comments (0)