Virtual Environment for Python

How to Create Virtual Environment for Python Development?

First we need to understand that why do we need virtual environment. It helps us to create isolated environment for python development. 
Let's try to understand problem without virtual environment. You are working on two different project say Project A and Project B. Now Project A need pyarrow version 4.0.1 and Project B need 3.0.0 as dependency. If you have only one environment for development then you can keep one of them. Now using virtual environment we can have multiple environment let's say env 1 for project A and env 2 for project B, this way both of them will have their requirement version of package. 


Steps to create a virtual environment in Windows Machine.

Step 1. Install virtualevn using below command 
            Pip install virtualenv 

Step 2. Create a virtual environment "myenvA" 
          > virtualenv myenvA

Step 3. Activate virtual environment. 
         >  myenvA\Scripts\activate
            or
        > workon myenvA

Step 4. Deactivate virtual environment.
        > deactivate 

If you need additional wrapper functions which will help in creating and managing virtualenv then install 

pip install virtualenvwrapper-win for windows machine. 
Now you can use 
>lsvirtualenv 
To list down all the virtual environment available in your machine. 
>workon virtualenv_name 
To activate one virtual environment.
>mkvirtualenv 
To create virtual environment.
> deactivate
In order to deactivate virtual environment.

Comments

Popular posts from this blog

Reading QR code in Python

Git Command

\r issue in shell script