Anaconda Installation

Anaconda is a unique python distribution that is geared towards data analytics, easy access of virtual environments and more. It is the default go-to that we use for MIG.

What is a Python Distribution?

As you probably know, python comes in many and different forms. You have python 3.8 python 2.7 python 3.9 and so many other versions. Not only that, but you have a wide variety of python distributions that have various supports for things like venv, packages, and more. With this in mind, there is a desire and need to standardize all of our environments that we are trying to work on so that we can easily debug each other's work without the fear that a package simply does not run on our local computer.

Note: MIG uses Python versions >= 3.7. We DO NOT use your local MacOS Python version of 2.7, so it is all the more important for you to go through this tutorial.

What is Anaconda?

Anaconda is a distribution of the Python that focuses primarily on scientific computing, that aims to simplify package management and deployment. This means better integrations with specific packages, faster downloads, optimized distributions, and easy environment creations.

Benefits of Using Anaconda Over Base Python

Package Management

Using Anaconda, there are much better ways of installing packages that can work across various platforms. Python is a C-based language, and C runs differently on a wide variety of operating systems. With Conda and their package servers, certain packages are automatically configured by Conda to work across systems. Examples include scikit-learn numpy pandas and many more scientific packages that you might be familiar with.

Most of the time, you are recommended to actually use $ conda install <package-name> and only defaulting to $ pip install <package-name if the certain package you want is not supported by conda tooling.

For more information related to the conda overall package, check out their package repository.

Containerized Environment Creation

If you are familiar with docker or venv this is the same exact thing. Conda offers the ability to create custom environments that can be tailored to varying projects. For example, I personally have multiple conda environments for various project teams here at MIG (one for the Platform, and one for Momentum). This way, requirements are not mixed, so you know exactly which packages are being used and which are not. In addition, this allows you to use varying python versions depending on your needs.

Make sure you understand this well. We will go over this later in the tutorial

Installing Anaconda

First, head over to the Anaconda distribution and download Anaconda for your local computer.

Downloading the Distribution

Downloading the distribution should produce an easy to understand interface where you are able to do everything via the installation (including adding Anaconda to the PATH, setting up installation locations, etc.)

Key Notes About Installation and PATH Setup

Despite suggestions about not installing Anaconda to the PATH, we do recommend adding it to the PATH as this will make your life much much easier (as you will be able to access the conda command directly from your terminal). On Macs, make sure you select this option during installation (I believe Windows is the same).

Recent installations should allow you to simply run conda init and that should also help set things up.

Verification

In order to verify everything is set up correctly, try opening up a terminal and running

$ conda info

And you should receive output like so:

$ conda info
     active environment : base
    active env location : /Users/brandonfan/code/anaconda3
            shell level : 1
       user config file : /Users/brandonfan/.condarc
 populated config files : 
          conda version : 4.7.12
    conda-build version : 3.18.9
         python version : 3.7.4.final.0
       virtual packages : 
       base environment : /Users/brandonfan/code/anaconda3  (writable)
           channel URLs : https://repo.anaconda.com/pkgs/main/osx-64
                          https://repo.anaconda.com/pkgs/main/noarch
                          https://repo.anaconda.com/pkgs/r/osx-64
                          https://repo.anaconda.com/pkgs/r/noarch
          package cache : /Users/brandonfan/code/anaconda3/pkgs
                          /Users/brandonfan/.conda/pkgs
       envs directories : /Users/brandonfan/code/anaconda3/envs
                          /Users/brandonfan/.conda/envs
               platform : osx-64
             user-agent : conda/4.7.12 requests/2.22.0 CPython/3.7.4 Darwin/20.6.0 OSX/10.16
                UID:GID : 502:20
             netrc file : None

Basic Conda Commands

Creating a New Environment

This is the most important command to understand in Anaconda. To create the environments that we mentioned above, you will want to follow the process below:

$ conda create --name=<environment-name> python=<python-version> <any packages>

This should create the initial environment for you with the specific name, python version, and more.

From there, you should be able to activate your environment.

Activating Your Environment

Simply run $ conda activate <environment-name> , you should then see this in your terminal on the left:

Your environment name --> (new-environment) username@hostname ~ $ 

Installing Packages from requirements.txt

Typically, when you are working in teams, you will have some sort of requirements.txt that represents all the packages you are using. To install these packages using anaconda, simply do

$ cd /path/to/directory
$ conda install --file requirements.txt

Exporting to requirements.txt

To export your environment to an environment config, you simply can run

$ conda activate <environment-name>
# this creates a requirements.txt in your cwd
$ conda list -e > requirements.txt 

Last updated