Skip to main content

How to Create Virtual Environment?

So, what is virtual environment actually? The main purpose of Python virtual environments is to create an isolated environment for Python projects. This means that each project can have its own dependencies, regardless of what dependencies every other project has.


For example, I create a virtual environment(v.env) named env_1. Inside this env_1, I install python 3.5 and tensorflow 1.8.

Then I can create another v.env named env_2. In env_2, I install python 3.6 and tensorflow 1.10.


Using Virtual Environment

If I want to use python 3.6 and tensorflow 1.10, I can use python.exe file in env_2 to run my python script. If I wish to use python 3.5 and tensorflow 1.8, I can use python.exe file in env_2 to run my python script.


Without Virtual Environment

I install python 3.6 and tensorflow 1.10 in the system, and I wish to use tensorflow 1.8, I have to uninstall tensorflow 1.10 and install tensorflow 1.8 in order to use tensorflow 1.8 library.


Can you note the difference?


Here's the way to create virtual environment.

Reference: https://conda.io/docs/user-guide/tasks/manage-environments.html

1. Download and install anaconda from https://www.anaconda.com/download/.

2. Open command prompt.

3. Create
     conda create -n yourenvname


4. Activate
     activate yourenvname


5. Install package
     conda install [package]

  pip install [package] //Some package need to be installed using pip


6. Deactivate
     deactivate


7. Delete a no longer needed virtual environment
      conda remove --n yourenvname --all


You can trace where is your virtual environment from command prompt after you create the virrtual environment.

By default: C:\Users\USER\AppData\Local\conda\conda\envs\yourenvname

Comments

Popular posts from this blog

Select Your Virtual Environment to be Used Using Pycharm

Pycharm is my favorite python IDE . One of the reason is because I can select which virtual environment I want to use easily. You can download it from here, https://www.jetbrains.com/pycharm/download/. I am using Community version. To select you virtual environment , go to File > Settings Project > Project Interpreter > Select 'Show All' Choose you python.exe file in your virtual environment. Check my post on How to Create Virtual Environment if you don't know how to get it. Done.