Skip to main content

Adding a Python Version

On this site, you will find a step-by-step guide on adding a custom Python Version to the instance.

We will add an older version Python 3.8, to our instance as an example.

Ubuntu

PPA Method

The first and easiest solution for Ubuntu users would be to import the deadsnakes team Launchpad PPA.
This will always contain the latest updates for Python and all extra packages that may be required.

  1. Install the prerequisite for adding custom PPAs:
apt update && apt -y install software-properties-common
  1. Add the deadsnakes/ppa to your APT package source list:
add-apt-repository ppa:deadsnakes/ppa -y
  1. Install Python 3.8:
apt update && apt -y install python3.8

Debian

Install Dependencies

First, we need to install the required dependencies to be able to build Python 3.8 from the source.

apt update && apt -y install build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev

Compiling from Source

Python Releases

All Python Releases can be found on the following site: https://www.python.org/downloads/

  1. Download the source for Python 3.8.
wget https://www.python.org/ftp/python/3.8.13/Python-3.8.13.tgz
  1. Extract the downloaded tarball:
tar xf Python-3.8.13.tgz
  1. Configure with the flag --enable-optimizations:
cd Python-3.8.13
./configure --prefix=/usr --enable-optimizations
  1. Run make to start the compile process:
make
  1. Install Python 3.8 via altinstall, which maintains the default Python binary path in /usr/bin/python.
make altinstall
  1. Remove the source and the tgz:
rm -rf Python-3.8.13 Python-3.8.13.tgz
  1. Done! Python 3.8 has been installed and is now available to select in CloudPanel.

Remove Dependencies

apt --purge remove zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libreadline-dev libffi-dev libsqlite3-dev libbz2-dev