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
Section titled “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.
Requirements
Section titled “Requirements”- You must have a compiler and development tools installed on your server.
Configuring a newer Python version on managed servers
Section titled “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.tgztar xvzf Python-3.12.8.tgzcd Python-3.12.8- Compile and install Python to your home directory:
./configure --prefix=$HOMEmakemake install- Configure your shell to use the new Python version (replace
usernamewith your account username):
echo 'alias python3="/home/username/bin/python3.12"' > ~/.bashrcsource ~/.bashrc- Verify the new Python version:
python3 --versionUsing Python virtual environments
Section titled “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/activateConfiguring a newer Python version on unmanaged servers
Section titled “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.tgztar xvzf Python-3.12.8.tgzcd Python-3.12.8- Compile and install:
./configuremakemake 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"' > ~/.bashrcsource ~/.bashrc- Confirm the Python version:
python3 --versionMore Information
Section titled “More Information”For further details about Python versions, downloads, and documentation, visit Python.org.