Virtual Environment creation and basic management in conda

Steven Kyle
2 min readOct 10, 2021
Photo by Esteban Benites on Unsplash

Why you should use a virtual environment

Before starting your new data science projects you might want to consider creating a virtual environment. What is a virtual environment you ask? A virtual environment is an isolated environment that will keep the python interpreter, installed libraries, and installed scripts isolated. This is crucial if you decide to work on multiple projects on your device. This will make it so that the specifics libraries for each project will stay in the designated environment and changing libraries for one project will not affect a separate project that is being worked on.

How to create a virtual environment

One way to create a virtual environment is by using anaconda. To download anaconda you can follow the link here. A user guide for installation can be found here. Once you have downloaded and installed anaconda, we should check and make sure that it is installed. One way to check is to run

conda -V

in the command line. The command line should then output the version of conda that is installed.

Creating a virtual environment

Creating a virtual environment is very simple. To create a new virtual environment we just have to call on conda in the command line to create the environment. The code below would create a new environment with the name “NAME”.

conda create -n NAME

You have now created a new environment. We can now activate and use the new environment! But before we fire it up we should check and see if it was actually created.

Checking your environment list

To look through your list of env, the below code can be typed into the command line. This will produce a list of all environments you have created.

conda env list

Activating your new environment

We can now activate and spin up the virtual environment through the command line. To activate, the following code can be ran in the command line.

conda activate NAME

Once your environment is running all installed libraries, python versions and installed scripts will now be saved to the environment.

Deactivating your environment

To deactivate the environment once you are finished working on your project, the following line can be used in the command line.

conda deactivate

Helpful CheatSheet

Conda has many useful features to help create/manage your virtual environments. A very useful cheatsheet with helpful commands can be found here.

--

--

Steven Kyle

25 year old Texan in the midst of a career change into DataScience.