Skip to content

Instantly share code, notes, and snippets.

@nbbrdn
Last active October 26, 2023 01:28
Show Gist options
  • Save nbbrdn/15aa9c09233ce2f81765aa1d404d085c to your computer and use it in GitHub Desktop.
Save nbbrdn/15aa9c09233ce2f81765aa1d404d085c to your computer and use it in GitHub Desktop.
Building Python from source

Building Python from source

  1. Download the compressed source tarball from python.org by executing the following wget command:
wget https://www.python.org/ftp/python/3.9.18/Python-3.9.18.tgz
  1. Unpack the downloaded archive and navigate to the resulting directory:
tar -xvf Python-3.9.18.tgz
cd Python-3.9.18
  1. Configure the build process by executing the following command, specifying the desired installation prefix and enabling optimizations:
./configure --prefix=/home/nb/.python3.9 --enable-optimizations
  1. Compile the source code using the make command with parallel processing (e.g., using 8 threads):Compile the source code using the make command with parallel processing (e.g., using 8 threads):
make -j8
  1. Install the configured Python version system-wide, which may require administrative privileges:
sudo make altinstall
  1. Verify the successful installation by running Python and pip from the newly built version:
cd
./.python3.9/bin/python3.9
./.python3.9/bin/pip3.9
  1. Add the Python executable directory to your PATH environment variable for convenient access by modifying your .bashrc:
echo 'export PATH="$PATH:$HOME/.python3.9/bin"' >> ~/.bashrc
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment