Anaconda

Update 2019-07-01 - Added environment sharing


Introduction

Anaconda is a Python / R distribution for data science applications. It includes many packages for data analysis and machine learning all in one place. I will be using Anaconda for its package manager Conda and its integrated environments which allow non-pip packages to be installed, unlike python virtual environments.

Setting up Anaconda

In the following sections, I will describe my process to create an Anaconda environment suitable for data analysis and machine learning.

Download and install Anaconda

The first step to download the appropriate installer. Since I am using Linux, I will be using the Python 3 64-Bit (x86) Linux installer.

1
wget https://repo.anaconda.com/archive/Anaconda3-2019.03-Linux-x86_64.sh

To install Anaconda, run the following command in terminal and follow the default installer prompts:

1
bash ~/Downloads/Anaconda3-2019.03-Linux-x86_64.sh

Once installed, the base environment must be activated to use conda functions.

1
source ~/anaconda3/bin/activate

And to deactivate an environment use:

1
conda deactivate

Creating and removing an environment

Once activated, the command prompt should change to indicate which environment has been activated (in this case, the base environment). With the base environment activated, we can run the following to create a new environment (follow the default prompts):

1
conda create -n <env_name>

This will create a new environment within the ~/Anaconda3/envs/ folder.

Activate a new environment using:

1
conda activate <env_name>

To remove an environment:

1
conda remove -n <env_name> --all

Listing all available environments

A list of all created environments can shown by running:

1
conda env list

or

1
conda info -e

Installing Packages in our Environment

Packages will be installed in the current environment. So we must first activate our desired environment and install packages using:

1
2
conda activate <env_name>
conda install <pkg_name>

We can also search for packages using:

1
conda search <pkg_name>

And to see the packages installed within a specific environment:

1
conda list -n <env_name>

or use the following if it is the current activated environment:

1
conda list

Sharing Environments

Export environments using:

1
conda env export > <name>.yml

Then install using:

1
conda env create -f <name>.yml