Low Orbit Flux Logo 2 F

Build Python From Source On Linux

You might want to build Python yourself. It is usually easier to install a binary version or install it from a package manager but there are many reasons to build it yourself. Personally, I feel like it gives me more control and the ability to customize more.

Go here to find the latest version: https://www.python.org/downloads/source/

Pull it down like this:


wget https://www.python.org/ftp/python/3.9.5/Python-3.9.5.tgz

Unpack it and cd into the upacked directory like this:


tar xvfz Python-3.9.5.tgz
cd Python-3.9.5/

The value of prefix is the directory where it will be installed when you run “make install”. The “make” command builds and the “make install” command installs it. If you specify an install directory that you don’t own ( ex. /opt/Python-3.9.5 ) you will need to use sudo. There are probably other options that you might want to use. Also, you might want to have SSL libraries available before building. You can build it like this.


./configure --prefix=/home/user1/python3 --enable-optimizations
make
make install

This will give you Python 3 and Pip 3 by default. You can find and run them from here.


/home/user1/python3/bin/python3
/home/user1/python3/bin/pip3

You can add this new bin directory to your path with a higher priority than other directories by specifying it first like this:


export PATH=/home/user1/python3/bin:$PATH

You can verify that python3 and pip3 now point to the newly installed version and not the version that comes with your system like this.


which python3
which pip3

You should now also be able to run these commands like this.


python3
pip3