Creating Create Python Virtual Environment on your respective Linux Distribution is a good idea because it provides a isolation environment for particular python app on a single Linux distribution. You can also host multiple python app on a single host that also increases the security of your python apps by providing different python environment for different apps. In this guide you will learn how to create a Python Virtual Environment using virtualenv tool and install python apps using installers like pip. This guide is also useful if you plan to install more than one python apps on your respective Python Virtual Environment.

Step 1 : Installing required dependencies
On Ubuntu
$ sudo apt-get install python-pip
On CentOS

Note: To install PIP installer it is required to install the EPEL repo on CentOS

$ sudo yum install epel-release && sudo yum install python-pip
Step 2 : Create a Python Virtual Environment installation directory
On Ubuntu
$ mkdir /home/techbrown/python
On CentOS

Note: Due to syslinux in CentOS 7 it is better to install the Python Virtual Environment on location /var/www/html

$ mkdir /var/www/html/python
Step 3 : Now change the directory to Python Virtual Environment installation directory
On Ubuntu
$ cd /home/techbrown/python
On CentOS
$ cd /var/www/html/python
Step 4 : Now install virualenv using PIP installer
$ sudo pip install virtualenv
Step 5 : Now Create a Python Virtual Environment

Here pythonenv is the installation directory of Python Virtual Environment

$ virtualenv pythonenv
Step 6 : After Creating now activate Python Virtual Environment using command
$ source /pythonenv/bin/activate
Step 7 : Now Install Python apps on Python Virtual Environment

After installing the python virtual environment now you are ready to install any python apps on your respective distribution with ease using pip command

(pythonenv) $ pip install django
Step 8 : If all done now deactivate the Python virtual environment by typing
$ deactivate

That’s all for now.

How to Harden SSH to Secure a Linux VPS Server

Previous article

How to Fix Broken Packages on Ubuntu / Debian

Next article

You may also like


Leave a reply

Your email address will not be published. Required fields are marked *

More in Linux