How to install virtualenv python for flask app on cPanel base shared hosting

As we know shared hosting doesn’t have python script on the cPanel. But the base system has python and already installed. If we can access SSH on cPanel we can run flask python and other python scripts too. It’s not too tough and for this process, we don’t need root user permission.

How to install virtualenv python for flask app on cPanel base shared hosting

  1. SSH login (example: HostGator)

By default Hostgator SSH supported login port 2222

Here is how to login connect to SSH. Goto your terminal (Mac or Linux) and type following command by giving your domain and cPanel username.

ssh -p 2222

Then type your Cpanel password. After login, you will see your terminal shell change to your cPanel shell. Type the command to see your files and folders

ls -al

ls command for showing files and folders, however adding with -al you can see all the files and folders including hidden and special characters also.

Let’s check first in your cPanel python installed or not. It is most important. To see python info type following command.

which python

This command will show you a directory where python installed by default in a system. In my case, my default python installed on the directory that shows in this picture.

You can check your python version by typing this command.

python -V


python --version

We can’t write in our root directory where python installed using shared hosting. So we need to install virtual environment for python. First, we need to create a folder for that. We can create a folder by using cPanel login then file manager. I use the terminal for my case. Here is the command for creating and entering the created folder directory.

First check where are you now. To know your current directory type the command.


This command will show you where are you now. In my case, I’m in my user folder. Let’s create a folder.

mkdir foldername

a new folder will create a name of “foldername“. You can use any name for that folder. In my case, my folder name “alam_scripts

To enter that folder type

cd foldername

Now we will download the scripts for a virtual environment of python. following commands

curl -O

This command will download a python package of virtualenv.

after that let’s extract and enter the downloaded directory.

gzip -cd virtualenv-12.0.7.tar.gz |tar xf -

virtualenv-12.0.7.tar.gz extracted now enter the folder of virtualenv-12.0.7

cd virtualenv-12.0.7

install python on your virtual environment following this command.

python2.7 install --user

after that create a virtual environment for your python project.

For that follow the commands. We are in our downloaded folder. using this command it will create a virtual python environment folder. In my case “venv” is the virtualenv of my python.

~/.local/bin/virtualenv venv --python=python2.7

Let’s activate our virtualenv python.

source venv/bin/activate

Did you see any changes of your terminal? Here are the changes after activation of python virtualenv

Now install flask python packages.

pip install flask

This command will install python flask packages on your venv folder.

For now, deactivate your python virtualenv. Commands are below.


We are almost done.

#Last Part: How to run Flask python app on shared hosting cPanel using SSH

Read my second post.

How to install virtualenv python for flask app on cPanel base shared hosting

Leave a Comment

Contact Us

We're not around right now. But you can send us an email and we'll get back to you, asap.

Not readable? Change text. captcha txt