Virtual Environment Setup And General Actions Using Anaconda - UGuntupalli/GeneralWorkflow GitHub Wiki

A virtual environment is a networked application that allows a user to interact with both the computing environment and the work of other users. Email, chat, web-based document sharing applications are all examples of virtual environments. Simply put, it is a networked common operating space. It is good practice to setup a virtual environment for each project to keep things isolated and avoiding spill-overs and unnecessary overhead. So, it is very helpful to get familiar with the process of setting up a virtual environment. While there are a lot of different virtual environment managers that are available and they have different requirements and processes, to keeps things uniform, straightforward and simple, a unified approach would be helpful. This is a very helpful resource for common questions regarding Virtual Environments using Anaconda.

Setting Up A New Virtual Environment From Scratch

Using Anaconda Prompt

Anaconda Prompt is a command line editor which runs using cmd.exe is the command line interface to Anaconda. Anaconda comes pre-loaded with an environment called base. This environment contains some of the most used python packages in it. Following are a few helpful steps:

  1. Create a new environment called demo

conda create --name demo

Anaconda_Prompt_New_Virtual_Environment

  1. At this point, besides the default base environment, we have also created a new virtual environment called demo. To get a list of all the environments, we can do the following.

conda info --envs

List_Of_Conda_Virtual_Environments

  1. As you will notice, the current active virtual environment is the default base environment. In order to activate a virtual environment, the following command could be used. You will notice upon the execution of the command, that the command prompt now has been set to demo which means that the environment has been activated

conda activate demo

Activate_Virtual_Environment

  1. When an environment is activated, we could check the packages that are already installed in the environment

conda list

List_Of_Packages_Installed

As expected, this environment does not have any packages installed. Let us install a few packages and then try the same command again

conda install pip

conda list

Pip_Install

Pip_Install_Conda_List

Using Anaconda Navigator

  1. Create a new environment called demo

New_Environment_Navigator

  1. Install a new package in the virtual environment

Install_New_Package_Anaconda_Navigator

Install_Pip_Anaconda_Navigator

Setting Up A New Virtual Environment From environment.yml

Typically, when using pre-developed packages all the required dependencies will be distributed using an environment.yml file. Another popular option is requirements.txt, however typically while using Anaconda environment.yml is the commonly used option. The following steps outline how to install a virtual environment using both Anaconda Prompt as well as Anaconda Navigator.

Using Anaconda Prompt

Navigate to the location where the environment.yml file exists. Run the following command to install the virtual environment

conda env create -f environment.yml

Anaconda_Prompt_Environment_yml

Using Anaconda Navigator

Anaconda_Navigator_Environment_yml