In this tutorial, we will see how to build customized python version from source on Ubuntu and how to install this customized python version in our local system.
We will see several install options - install as main python interpreter,
install it as alternative python interpreter. The last option is creating and installing a deb package with the help of
checkinstall - This allows easily remove the package with one step and to install the resulting package upon multiple machines.
# sudo apt update # sudo apt -y install build-essential checkinstall
# sudo apt install -y libreadline-gplv2-dev libbz2-dev libncursesw5-dev libgdbm-dev zlib1g-dev liblzma-dev libsqlite3-dev libssl-dev libffi-dev
Or select the modules you want to build and install only the relevant development libs
||Nice to have in the interactive interpreter|
||use if you get : Failed to build these modules: _ctypes|
Suppose you want to build python 3.7.2:
~/# mkdir py && cd py ~/py# wget https://www.python.org/ftp/python/3.7.2/Python-3.7.2.tgz ... ~/py# tar xzf Python-3.7.2.tgz && cd Python-3.7.2 ... ~/py/Python-3.7.2#
Issue the following command to build python
~/py/Python-3.7.2# ./configure --enable-optimizations ... ~/py/Python-3.7.2# make ...
If everything was OK, you can now use built python:
~/py/Python-3.7.2# ./python --version Python 3.7.2