Thursday 11 June 2020

How to create a Virtual Environment in Python

Why do you need to create a Virtual Environment?

Sometimes, we need to have some dependencies of your project to be isolated
from dependencies present in the system site to avoid conflicts and Virtual 
Environment lets you do this.

Creating a virtual environment lets you have your own independent set of 
installed Python packages in your site directories which is apart from system
site directories. Virtual Environment lets you create an isolated environment 
for your python projects.


Creating a Virtual Environment :

Step 1: Install Virtual Environment package:

pip install virtualenv


Step 2: Create a new directory to work with and head over there:

mkdir venv
cd venv


Step 3: Now, create a new Virtual Environment in this directory

virtualenv myvenv

This creates a new virtual environment with the name "myvenv".


For using this Environment's packages you need to activate it.

Step 4: Activate the environment 

myvenv\Scripts\activate

Now you are in virtual environment and ready to go with it.


Step 5: Deactivate the virtual environment

deactivate

20 comments:

  1. Is there any other method also?

    ReplyDelete
    Replies
    1. No, you always have to install virtualenv or venv module to create virtual environment in python. Thank you for your valuable question.

      Delete
  2. Great Blog...Really it's so helpful...Keep It Up🙂

    ReplyDelete
  3. User friendly tutorial....no hurdle while following the above said steps

    ReplyDelete
  4. Really helpful

    ReplyDelete