Configuring and Using a Newer Version of Python

This guide explains how to download, compile, and configure a newer Python version on your hosting account. This is useful if the server’s default Python version is older than what your application requires.


When to use a newer Python version

  • Managed servers (shared or reseller) where the installed Python version is older than required.

  • Unmanaged servers where package repositories contain older Python versions.

Note: This applies to all cPanel hosting accounts.

Requirements

  • You must have a compiler and development tools installed on your server.


Configuring a newer Python version on managed servers

  1. Log in to your account using SSH.

  2. Download and extract the Python source code:

cd ~
wget https://www.python.org/ftp/python/3.12.8/Python-3.12.8.tgz
tar xvzf Python-3.12.8.tgz
cd Python-3.12.8
  1. Compile and install Python to your home directory:

./configure --prefix=$HOME
make
make install
  1. Configure your shell to use the new Python version (replace username with your account username):

echo 'alias python3="/home/username/bin/python3.12"' > ~/.bashrc
source ~/.bashrc
  1. Verify the new Python version:

python3 --version

Using Python virtual environments

Python 3 includes built-in support for virtual environments using the venv module.

  • To create a virtual environment:

python3 -m venv testenv
  • To activate it:

cd testenv && source bin/activate

Configuring a newer Python version on unmanaged servers

If the system repositories have an older Python version, you can compile it from source:

  1. Log in to your server via SSH as root.

  2. Download and extract the source code:

cd ~
wget https://www.python.org/ftp/python/3.12.8/Python-3.12.8.tgz
tar xvzf Python-3.12.8.tgz
cd Python-3.12.8
  1. Compile and install:

./configure
make
make install
  1. Configure your shell to use the new executable (replace executable_path with the path to the compiled Python executable, e.g., /usr/local/bin):

echo 'alias python3="/executable_path/python3.12"' > ~/.bashrc
source ~/.bashrc
  1. Confirm the Python version:

python3 --version

More Information

For further details about Python versions, downloads, and documentation, visit Python.org.

Was this answer helpful? 0 Users Found This Useful (0 Votes)

Powered by WHMCompleteSolution