How to Use Anaconda Environments

Share this post

In this introduction to Anaconda Environments, you will learn how to use, create, and manage python environments using the Anaconda distribution.

What is Anaconda?

Anaconda is a Python distribution for data science and machine learning.

Why Use Virtual Environments?

The main purpose of Python virtual environments is to create isolated environments where each project is independent from the other, using its own dependencies.

For example, one project could use Python 2.7 and the other Python 3.6. You could also use different versions of the same package in different projects.

Conda Basics

Check if Conda is Installed

Open the Terminal or Command line and run the conda -V command.

$ conda --version
#or
$ conda -V

If nothing appears. You will need to install Anaconda.

How to Install Anaconda

The first step is to install Anaconda if you have not done yet. Read this guide to show you how to Install Python With Anaconda [On Windows].

Check Installed Packages

The Anaconda distribution install packages automatically. To check what was installed and which version use the following command.

$ conda list

Environment Basics

Get a List of the Environments

To get a list of all available environments on your machine use:

$ conda env list

Create a New Environment

To create a new python environment use the following command:

$ conda create --name environment-name

Create an Environment Using a Specific Version of Python

Some packages have not been updated to Python 3. If you want to use them, you need to create an environment using Python 2.7.

$ conda create -n <environment-name> python=2.7.0

Remove an Environment

You can remove an environment using the following command:

$ conda env remove --name <environment-name>
# or
$ conda env remove -n <environment-name>

Activate an Environment

Before you can use an environment, you need to activate it. You can activate your environment using:

 $ conda activate <environment-name>

Deactivate an Environment

If you want to deactivate the environment.

$ conda deactivate

Clone an Environment

You can create a clone of an existing environment if you want to apply minor changes to the environments. This one clones the root/base environment.

$ conda create --name <environment-name> --clone base

Check Installed Packages in Environment

To check packages in an existing environment, use the following command:

$ conda list --name <environment-name>

You can also look at a specific packages.

$ conda list --name <environment-name> 'pandas|scikit-learn'

Search for a Package

$ conda search matplot

Remove a Package from Specific Environment

$ conda remove -n <environment-name> pandas

Add Package in Specific Environment

$ conda install -n <environment-name> pandas=0.25.0

This is it for our introduction of Anaconda Environments.