This article describes how to configure and use a newer Python version. You may want to do this if:
Depending on the managed server where your account is located, there may be an older version of Python installed. If you want to run a newer version of Python, you can compile it from the source code.
To compile Python from the source code, follow these steps:
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 ./configure --prefix=$HOME make make install
To configure your shell environment to use the new compiled executable, type the following commands. Replace username with your own A2 Hosting account username:
echo 'alias python3="/home/username/bin/python3.12"' >> ~/.bashrc
source ~/.bashrc
To confirm your account is configured to use the new version, type the following command:
python3 --version
In older Python versions, you needed to install the virtualenv program to create and use virtual environments. With Python 3, support for virtual environments is included by default. After you install your compiled version of Python using the procedure above, you can create virtual environments immediately by using the venv module. For example:
python3 -m venv testenv
This command creates a virtual environment named testenv. To activate the new environment, type the following command:
cd testenv && source bin/activate
The package repositories for your Linux distribution may contain an older version of Python. If you want to run a newer version of Python, you can compile it from the source code. To do this, follow these steps:
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 ./configure make make install
To configure the shell environment to use the new compiled executable, type the following commands. Replace executable_path with the path to the compiled Python executable (for example, /usr/local/bin):
echo 'alias python3="/executable_path/python3.12"' >> ~/.bashrc
source ~/.bashrc
To confirm your account is configured to use the new version, type the following command:
python3 --version
For more information about Python, please visit https://www.python.org.
Subscribe to receive weekly cutting edge tips, strategies, and news you need to grow your web business.
No charge. Unsubscribe anytime.
Did you find this article helpful? Then you'll love our support. Experience the A2 Hosting difference today and get a pre-secured, pre-optimized website. Check out our web hosting plans today.
We use cookies to personalize the website for you and to analyze the use of our website. You consent to this by clicking on "I consent" or by continuing your use of this website. Further information about cookies can be found in our Privacy Policy.