Installing Python is usually not problematic, but in certain scenarios we do not want to alter the system or we need a specific version of Python but the server is very old and does not allow its installation.
In these cases, we can choose to manually compile Python and install it in a local directory, so the system will continue to function normally and we can use the version of Python we want.
If we are on an Ubuntu system, we will install the necessary dependencies to compile Python.
NOTE: In case of Gentoo or FreeBSD, everything is already installed.
wget https://www.python.org/ftp/python/3.9.0/Python-3.9.0.tgz
tar -xvf Python-3.9.0.tgz
cd Python-3.9.0
./configure --prefix=$HOME/Python-3.9.0/Python --enable-optimizations
make -j8
make install
We check the installed version:
Python 3.9.0
Everything we install using pip will be done in our local directory:
And that’s it, Python version 3.9.0 with libraries installed using pip in a self-contained directory.