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:
- Create a new environment called
demo
conda create --name demo
- At this point, besides the default
base
environment, we have also created a new virtual environment calleddemo
. To get a list of all the environments, we can do the following.
conda info --envs
- 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 todemo
which means that the environment has been activated
conda activate demo
- When an environment is activated, we could check the packages that are already installed in the environment
conda list
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
Using Anaconda Navigator
- Create a new environment called
demo
- Install a new package in the virtual environment
environment.yml
Setting Up A New Virtual Environment From 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