How to Use Python on AlmaLinux, Rocky Linux, Ubuntu, and CloudLinux 9
Last modified: January 7, 2025
Overview
This document explains how the AlmaLinux OS, Rocky Linux™, Ubuntu®, and CloudLinux™ 9 operating systems handle the python
command. Due to changes in how these operating systems call this command, you may need to adjust your code.
We removed Python 2 in cPanel & WHM version 126. If your server runs cPanel & WHM version 126 or later, you must use Python 3.
Python on AlmaLinux, Rocky Linux, Ubuntu, and CloudLinux 9
Since Python 2 is now end-of-life and many systems use Python 3, the python
command may not refer to the correct version of Python. As many systems create an alias for the python
command that refers to a specific version of Python, this alias may not point to the correct version of Python for your system.
On AlmaLinux, Rocky Linux, Ubuntu, and CloudLinux 9 servers, the /usr/bin/python
command does not exist. This means that the python
command will not work. Instead, you must specify the version of Python installed on your system that you wish to use.
On AlmaLinux 8, Rocky Linux 8, and Ubuntu servers that run cPanel & WHM version 124 or earlier, you may specify either Python 2 or Python 3. On servers running AlmaLinux 9, Rocky Linux 9, or CloudLinux 9, you must specify Python 3.
- To run Python 2, use the
python2
command. - To run Python 3, use the
python3
command.
Trouble with your own code
If you experience trouble running Python code that you control, make certain that your code refers to the specific version of Python installed on your server rather than just /usr/bin/python
.
Because Python 2 no longer receives updates and we removed it in cPanel & WHM version 126, we strongly recommend that you update your code to use Python 3 syntax. Python includes a conversion tool that will perform many of the necessary updates to convert your code from version 2 to 3.
Trouble with code from another source
If you have trouble with code that you do not control, contact the provider of the code and ask them to update their code to refer to a specific version of Python.
To work around this issue, you can create a symlink or use alternatives to redirect the /usr/bin/python
command to the version of Python installed on your server.
Use alternatives to redirect your python command to Python 3
On AlmaLinux, Rocky Linux, and CloudLinux 9 servers, to use alternatives
to redirect the python
command to Python 3, run the following command:
alternatives --install /usr/bin/python python /usr/bin/python3 1
On Ubuntu servers, to use update-alternatives
to redirect the python
command to Python 3, run the following command:
update-alternatives --install /usr/bin/python python /usr/bin/python3 1
Use symlinks to redirect your python command to Python 3
On AlmaLinux, Rocky Linux, Ubuntu, and CloudLinux 9 servers, to create a symlink to redirect the python
command to Python 3, run the following command:
ln -s /usr/bin/python3 /usr/bin/python