# Install Anaconda for Machine Learning and Data Science in Python

## Introduction

This is a reference post.

I've realized that I'm explaining how to install Anaconda over and over again in most of my posts, often messing up with the instructions!

So to make it easier for me and, most importantly, safer for you, I'm summarizing the instructions in this short post, and I will refer to it from now on.

I'll present you with two installation methods for Anaconda:

• Graphical installation of Anaconda: recommended if you are new to Anaconda.
• Command line installation of Miniconda: recommended if you want a fast and light install, and if you want to work with the command line.

## What is Anaconda?

As stated on Anaconda's website:

With over 6 million users, the open source Anaconda Distribution is the fastest and easiest way to do Python and R data science and machine learning on Linux, Windows, and Mac OS X. It's the industry standard for developing, testing, and training on a single machine.

In a nutshell, the anaconda team maintains a repository of more than 1400 data science packages, all compatible, and provides tools to install a version of python and these packages at the push of a button, and under five minutes.

In particular, Anaconda contains:

• scikit-learn : one of leading machine-learning toolkits for python. It will provide an easy access to the handwritten digits dataset, and allow us to define and train our neural network in a few lines of code
• numpy : core package providing powerful tools to manipulate data arrays, such as our digit images
• matplotlib : visualization tools, essential to check what we are doing
• and much, much more!

## Graphical installation of Anaconda

• Choose either the python 3.X or the python 2.X version. Please make sure to chose the version specified in the tutorial you want to run. If you don't know, take the python 3.X version
• If you're using Windows or Linux, make sure to pick the 64 bit installer if you have a 64 bit system.

Then run the installer, and finally start the Anaconda Navigator. On windows, you can find it by clicking the windows start button, and typing anaconda.

In the Anaconda Navigator, you can click on the Environments tab and then select the base (root) environment to see which packages are installed, and to install additional packages. You can also create new environments as shown below.

Finally, to start using it, go to the Home tab and launch the jupyter notebook. This will redirect you to the jupyter notebook main page in your browser.

You can now create and load jupyter notebooks.

You're done!

## Command line installation of Miniconda

• Choose either the python 3.X or the python 2.X version. Please make sure to chose the version specified in the tutorial you want to run. If you don't know, take the python 3.X version
• If you're using Windows or Linux, make sure to pick the 64 bit installer if you have a 64 bit system.

On linux, you can download the bash installer from the command line with wget like this (replace with the link you need from the Miniconda page):

wget https://repo.anaconda.com/miniconda/Miniconda3-latest-Linux-x86_64.sh


curl -O https://repo.anaconda.com/miniconda/Miniconda3-latest-MacOSX-x86_64.sh


After this is done, open a bash terminal and type the following (use the name of the installer that you have just downloaded)

bash Miniconda3-latest-MacOSX-x86_64.sh


Answer all questions, and you're done with the installation.

Then, you can use the command line to:

• create conda environments
• select the version of python you want
• install the packages you need.

I usually do everything in one go like this:

conda create -n testenv python=3.7 ipython


This creates a new environment called testenv based on python 3.7, and with the ipython package.

You can then activate the environment, and test that things are as you expect:

conda activate testenv
conda list

# packages in environment at /Users/cbernet/miniconda3/envs/testenv:
#
# Name                    Version                   Build  Channel
appnope                   0.1.0                    py37_0
backcall                  0.1.0                    py37_0
ca-certificates           2019.5.15                     0
certifi                   2019.6.16                py37_0
decorator                 4.4.0                    py37_1
ipython                   7.6.0            py37h39e3cac_0
ipython_genutils          0.2.0                    py37_0
jedi                      0.13.3                   py37_0
libcxx                    4.0.1                hcfea43d_1
libcxxabi                 4.0.1                hcfea43d_1
libedit                   3.1.20181209         hb402a30_0
libffi                    3.2.1                h475c297_4
ncurses                   6.1                  h0a44026_1
openssl                   1.1.1c               h1de35cc_1
parso                     0.5.0                      py_0
pexpect                   4.7.0                    py37_0
pickleshare               0.7.5                    py37_0
pip                       19.1.1                   py37_0
prompt_toolkit            2.0.9                    py37_0
ptyprocess                0.6.0                    py37_0
pygments                  2.4.2                      py_0
python                    3.7.3                h359304d_0
setuptools                41.0.1                   py37_0
six                       1.12.0                   py37_0
sqlite                    3.28.0               ha441bb4_0
tk                        8.6.8                ha441bb4_0
traitlets                 4.3.2                    py37_0
wcwidth                   0.1.7                    py37_0
wheel                     0.33.4                   py37_0
xz                        5.2.4                h1de35cc_4
zlib                      1.2.11               h1de35cc_3


You see that python is indeed version 3.7, and that ipython is there. You can start ipython.

After Miniconda is installed, don't hesitate to create new environments not to mix things up. For example, I have a dozen environments: a python 3.X environment for this blog, a python 2.X one for some tasks at work, another one for activities related to OpenCV... And every time I write an article for this blog, I create a fresh environment to test the installation recipe, before deleting it right away.