How to Create Python Virtual Environment on Ubuntu 16.04 / CentOS 7

How to Create Python Virtual Environment on Ubuntu 16.04 / CentOS 7 / Debian 9 / RHEL 7 / SL 7 / OL 7. 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 16.04
$ sudo apt-get install python-pip
On CentOS 7

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

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

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 16.04
$ cd /home/techbrown/python
On CentOS 7
$ 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

Final Words

Congratulations now you have created Python Virtual Environment and fell free to test any python apps on your virtual environment now you have freedom to install more python apps with different python environment on a single distribution with ease. If you have any questions regarding this topics feel free to ask at comment section below.

Hot Right Now

Related Post

COMMENTS