Creating a Virtualenv in Python

Posted By : Ishaan Madan | 12-Jan-2017

What is Virtualenv?

 

A Python Virtual Environment, is basically an isolated location of Python which
enables a user to work on a particular project without any concern of influencing other projects

It enables version specific installations of Python for each project according to requirements.

Is Virtualenv Already installed

 

There might be a possibility that virtualenv is already present on the system. 

To verify it we may Run the command in our terminal
virtualenv --version
If it displays a version (eg: 1.6.1), it's already installed.
>>1.6.1

Installing Virtualenv

 

There are a various ways for installing virtualenv. Some of them are:
$ sudo apt-get install python-virtualenv

$ sudo easy_install virtualenv

$ sudo pip install virtualenv

Setting up and Using Virtualenv

 

Create a directory for the isolated environment
sudo mkdir ~/myvirtualenvironment
Create a folder for the application that comprises of a neat copy of Python,
 Run:
sudo virtualenv ~/myvirtualenvironment/myNewApp
Chnage the directory to the project and activate the virtual environment.
cd ~/myvirtualenvironment/myNewApp/bin
Activate the environment:
source activate
Note: The prompt of the shell will be changed to signify the active virtual environment. 
To exit the python virtualenv just run “deactivate” command.

Installing a package in active Virtualenv

 

Looking at the bin directory in our virtualenv, we will see easy_install which
is modified to put all the packages in the virtualenv’s site-packages 
directory.

To install an app in the Virtualenv, we may run:
pip install flask
We don't  use sudo since the files being installed are installed in the virtualenv

Thanks

 

Related Tags

About Author

Author Image
Ishaan Madan

Ishaan, a skilled technical project manager, excels at breaking down complex projects into manageable tasks. With a background in both technology and project management, he offers a unique perspective to every project he undertakes. His effective communication skills enable him to collaborate seamlessly with both technical and non-technical stakeholders, ensuring everyone is aligned towards shared objectives. He has hands-on experience in utilizing agile methodologies like Scrum and Kanban to drive project management and foster team collaboration. He leverages project management tools such as JIRA, Trello, and Clickup to monitor progress, manage tasks, and facilitate communication among team members and stakeholders. Moreover, his proficiency in full-stack development empowers him to comprehend the technical aspects of projects and provide guidance to developers when necessary. He demonstrates expertise in utilizing popular Python frameworks like Django and Flask, along with data analysis and manipulation libraries such as NumPy and Pandas. On the front-end, Ishaan adeptly employs JavaScript libraries like React and Angular to craft visually appealing and user-friendly interfaces. Additionally, he possesses proficiency in HTML, CSS, and JavaScript for designing responsive and mobile-friendly layouts.

Request for Proposal

Name is required

Comment is required

Sending message..