Skip to content

Instantly share code, notes, and snippets.

@mrsarm
Created January 31, 2023 17:28
Show Gist options
  • Save mrsarm/563b3027484dcb086d6d7c34ad21f986 to your computer and use it in GitHub Desktop.
Save mrsarm/563b3027484dcb086d6d7c34ad21f986 to your computer and use it in GitHub Desktop.

Install Python from sources

On Ubuntu or compatible:

sudo apt-get install build-essential libsqlite3-dev sqlite3 bzip2 libbz2-dev zlib1g-dev libssl-dev libffi-dev lzma liblzma-dev

Download Python source and install as normal user with (replace prefix path, e.g. /opt/py/python3.11):

./configure --enable-optimizations --prefix=/opt/py/python3.11
make -j8 build_all
make altinstall

The argument -j8 is optional and makes the execution of the jobs in parallel. The user has to have write access into the folder specified, and if does not exist yet, have write access to the parent folder, otherwise the last command has to be executed as root user.

Optional, create exec link at /usr/local/bin with:

sudo ln -s /opt/py/python3.11/bin/python3.11 /usr/local/bin/python3.11

Optional dependencies regarding what is needed:

  • gettext for Django.
  • postgresql-common and libpq-dev for psycopg2-binary.

Tested with Python 3.6, 3.8, 3.10 and 3.11. Based on answers found at https://askubuntu.com/questions/244544/how-do-i-install-python-3-3.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment