Knowledge Base Hub

Browse through our helpful how-to guides to get the fastest solutions to your technical issues.

Home  >  Web Hosting FAQ  >  Learn how to configure and use a newer version of Python
Top Scroll

Learn how to configure and use a newer version of Python

 3 min

This article guides you on how you can configure and use a new version of Python. You may need to do it when :
• You have a managed server account and you want to use new Python version than what is already installed on the server.

Note: This applies to all hosting accounts that have cPanel, including shared and reseller server.

• You have an unmanaged server account, and the package repositories for your Linux distribution contain an older version of Python.

Before proceeding with this article make sure that you have a compiler and other development tools installed on your server.

Let’s get started.

# Steps to configure managed servers

Your account can be located on a managed server that already has an older version of Python installed. So, if you wish to run a new version of Python, you can compile it by using this source code.
Perform the following steps to compile Python from the source code :

1. Using SSH, log in to your account.

2. Type following command in the command prompt :

cd~
wget https://www.python.org/ftp/python/3. 5. 2/Python-3. 5. 2. tgz
tar xvzf Python-3. 5. 2. tgz
cd Python-3. 5. 2
./configure --prefix=$HOME
make
make install

Note: This command explains how to install Python version 3.5.2. If you want to install a different version, then visit https://www.python.org/ftp/python/ to view the other versions that are available for download. Once you select a version, run the previous commands with the version number that you have selected at the place of 3.5.2.

3. To configure your shell environment and to use the new compiled executable, type the following command.

echo 'alias python3="/home/username/bin/python3.5" '>> ~/.bashrc
source ~/.bashrc

Replace the username with your MilesWeb hosting account username.

4. In order to confirm that your account is configured to use the new version, type the following command :

python --version

# Steps to install virtualenv

To create virtual environments by using your installed version of Python, you first need to install the virtualenv program. Type following command to do this :

cd ~/bin

python3.5 -m pip install virtualenv

You are then allowed to create a virtual environment by running the virtualenv program in the bin directory. For example: if you want to create a virtual environment named testenv, type the following command :

~/bin/virtualenv testenv

Type the following command, to activate the new environment.

source testenv/bin/activate

#Steps to configure unmanaged servers

There is a possibility that the package repositories for your Linux distribution may contain the older version of the Python. But, if you want to run the new version of Python, then you can compile it from the source code. Perform the following steps to do so:

1. Using SSH, log in to your account.

2. Type the following command in the prompt, as a root user:

cd~
wget https://www.python.org/ftp/python/3. 5. 2. Python-3. 5. 2. tgz

tar xvzf Python-3. 5. 2. tgz

cd Python-3. 5. 2

./configure

make

make install

3. In order to configure the shell environment and to use the new compiled executable, type the following command :

echo 'alias python3="/executable_path/python3.5" ' >> ~/.bashrc
source ~/ .bashrc

Replace executable_path with the path to the compiled Python executable (example, /usr/local/bin).

4. To confirm if your account is configured to use the new version, type the following command :

python --version

For more information about Python, visit https://www.python.org

Also Read :

1)How to Create the End User Access for Python and Ruby Selector?

For our Knowledge Base visitors only
Get 10% OFF on Hosting
Special Offer!
30
MINS
59
SECS
Claim the discount before it’s too late. Use the coupon code:
STORYSAVER
Note: Copy the coupon code and apply it on checkout.