Skip to content

Instantly share code, notes, and snippets.

@charbonnierg
Last active February 8, 2024 14:21
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save charbonnierg/fc805149c83f239f70dab055d409e868 to your computer and use it in GitHub Desktop.
Save charbonnierg/fc805149c83f239f70dab055d409e868 to your computer and use it in GitHub Desktop.

Build Python

Build & install the python version of your choice quicky on Ubuntu 20.04:

curl -sL https://gist.githubusercontent.com/charbonnierg/fc805149c83f239f70dab055d409e868/raw/build-python.sh | sudo bash -s 3.10.13

Notes

  • Python is installed using make altinstall so it is not available using python3 but only using python3.X

  • Python is built with the following flags:

    • --enable-optimizations
#!/usr/bin/env bash
set -euo pipefail
function installDeps {
apt-get update
apt-get install -y --no-install-recommends \
ca-certificates \
wget \
build-essential \
checkinstall \
libreadline-gplv2-dev \
libncursesw5-dev \
libssl-dev \
libsqlite3-dev \
tk-dev \
libffi-dev \
libgdbm-dev \
libgdbm-compat-dev \
libc6-dev \
libbz2-dev \
liblzma-dev \
uuid-dev
}
function buildPython {
PYTHON_VERSION="$1"
wget "https://www.python.org/ftp/python/$PYTHON_VERSION/Python-$PYTHON_VERSION.tgz"
tar -xzf "Python-$PYTHON_VERSION.tgz"
cd "Python-$PYTHON_VERSION"
./configure --enable-optimizations
make -j 8
make altinstall
}
installDeps
buildPython "$@"
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment