This page looks best with JavaScript enabled

Python self-contained in a local directory

 ·  🎃 kr0m

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.

apt install zlib1g-dev libssl-dev libncurses5-dev libsqlite3-dev libreadline-dev libtk8.5 libgdm-dev libdb4o-cil-dev libpcap-dev

NOTE: In case of Gentoo or FreeBSD, everything is already installed.

cd
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/bin/python3 -V

Python 3.9.0

Everything we install using pip will be done in our local directory:

Python/bin/python3 -m pip install ovh cymruwhois godaddypy dnspython --user

And that’s it, Python version 3.9.0 with libraries installed using pip in a self-contained directory.

If you liked the article, you can treat me to a RedBull here