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
-
Log in to your account using SSH.
-
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
-
Compile and install Python to your home directory:
./configure --prefix=$HOME
make
make install
-
Configure your shell to use the new Python version (replace
usernamewith your account username):
echo 'alias python3="/home/username/bin/python3.12"' > ~/.bashrc
source ~/.bashrc
-
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:
-
Log in to your server via SSH as root.
-
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
-
Compile and install:
./configure
make
make install
-
Configure your shell to use the new executable (replace
executable_pathwith the path to the compiled Python executable, e.g.,/usr/local/bin):
echo 'alias python3="/executable_path/python3.12"' > ~/.bashrc
source ~/.bashrc
-
Confirm the Python version:
python3 --version
More Information
For further details about Python versions, downloads, and documentation, visit Python.org.