Installing Python, Anaconda, and Atom

In this tutorial, we’ll go over how to set up all the tools you need to not only work effectively in Python, but also get going with the Jupyter ecosystem, which supports not only Python, but also R, Julia, and more.

Installing Atom

Before we install Anaconda, I would first suggest everyone install a good text editor if you don’t already have one. I recommend Atom, installation and setup directions for which can be found here.

Installing Anaconda

The first thing we need to do is download the Anaconda Python distribution. The Anaconda distribution is not the only way to get Python – indeed, there’s a good chance a version of Python is already installed on your computer – but the Anaconda installation does a number of very nice things:

  • Installs a clean installation of the latest version of Python

  • Installs of a large number of packages that are commonly used in scientific computing

  • Provides a “package manager” – a tool for installing new packages in the future and updating already installed packages.

To install Python, go to the Anaconda Download page, download and install the most recent Python 3.x version of Anaconda (as of June 2016, this was Python 3.7).

Installation Note for Mac Users

When installing, make sure to choose “Install for Me Only” when you have a choice of installation locations:

osx-install-destination

Installing for all users, or picking a location yourself seems to lead to lots of weird problems with the jupyter ecosystem.

Installation Note for Windows Users

One of the checkboxes during the Windows installation is “do you want to add Anaconda to your PATH?”. Although anaconda recommends against this, it is very helpful for using python using Cmder, so select yes. This is easy to change later if you ever feel the need.

If there’s a Python 3.7, why is there also a Python 2.7 available?

In 2000, Python 3 was first released. Python 3 fixed a lot of things people disliked about Python, but in the process it made some changes that meant code written in Python 2 would not work any more. To ease the transition to Python 3, both Python 2 and Python 3 have been supported for several years so people could keep running their Python 2 projects while they finished the transition. Almost everything is now in Python 3, so since you don’t have any old code to worry about, you want Python 3.

Using Anaconda with Oh-My-Zsh (Macs)

If you installed Oh-My-Zsh during the command line exercises (as suggested here, then Anaconda won’t work right away. The problem is that when you install Anaconda, it adds some code to the .bash_profile file in your user directory. The .bash_profile file contains code the is run every time you open a new bash command line session (as discussed at the end of Advanced Command Line), and the code Anaconda adds adds Anaconda to your PATH variable.

But Oh-My-Zsh doesn’t run the .bash_profile file when it opens; it runs the .zshrc file. So what we have to do is move the code Anaconda put in .bash_profile into .zshrc. You can do this as follows:

  1. Open .bash_profile and copy the block of text that begin with # >>> conda init >>> and ends with # <<< conda init <<<.

  2. Then open .zshrc, scroll to the bottom of the file, and past the text you copied from .bash_profile into .zshrc.

  3. Save that file, close your current session of Oh-My-Zsh, open it again, and test to see if you were successful by typing conda -h. If a conda helpfile gets printed out, you’re good!

Note: If you copy text from the nano editor (rather than open your file with atom) and the nano editor window is narrow, the ends of lines will be truncated when you paste the output (and will end with dollar signs ($)).

For example, if I highlight this text with my mouse and try to copy and paste it:

bash_truncated

I will get:

# added by Miniconda3 4.7.10 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/Nick/miniconda$
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/Users/Nick/miniconda3/etc/profile.d/conda.sh" ]; th$
        . "/Users/Nick/miniconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/Users/Nick/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

not

# added by Miniconda3 4.7.10 installer
# >>> conda init >>>
# !! Contents within this block are managed by 'conda init' !!
__conda_setup="$(CONDA_REPORT_ERRORS=false '/Users/Nick/miniconda3/bin/conda' shell.bash hook 2> /dev/null)"
if [ $? -eq 0 ]; then
    \eval "$__conda_setup"
else
    if [ -f "/Users/Nick/miniconda3/etc/profile.d/conda.sh" ]; then
        . "/Users/Nick/miniconda3/etc/profile.d/conda.sh"
        CONDA_CHANGEPS1=false conda activate base
    else
        \export PATH="/Users/Nick/miniconda3/bin:$PATH"
    fi
fi
unset __conda_setup
# <<< conda init <<<

(See how several lines are truncated and end in dollar signs?)

So if you’re using nano to open these files and edit, make sure the window is wide enough!

Your conda works if…

You can run conda -h from your command line and you see a helpfile print out like below instead of conda: command not found, you’re good!

bash-3.2$ conda -h
usage: conda [-h] [-V] command ...

conda is a tool for managing and deploying applications, environments and packages.

Options:

positional arguments:
  command
    clean        Remove unused packages and caches.
    config       Modify configuration values in .condarc. This is modeled
                 after the git config command. Writes to the user .condarc
                 file (/Users/Nick/.condarc) by default.
    create       Create a new conda environment from a list of specified
                 packages.
    help         Displays a list of available conda commands and their help
                 strings.
    info         Display information about current conda install.
    init         Initialize conda for shell interaction. [Experimental]
    install      Installs a list of packages into a specified conda
                 environment.
    list         List linked packages in a conda environment.
    package      Low-level conda package utility. (EXPERIMENTAL)
    remove       Remove a list of packages from a specified conda environment.
    uninstall    Alias for conda remove.
    run          Run an executable in a conda environment. [Experimental]
    search       Search for packages and display associated information. The
                 input is a MatchSpec, a query language for conda packages.
                 See examples below.
    update       Updates conda packages to the latest compatible version.
    upgrade      Alias for conda update.

optional arguments:
  -h, --help     Show this help message and exit.
  -V, --version  Show the conda version number and exit.

conda commands available from other packages:
  env
bash-3.2$

Change the Default Channel

One of the main purposes of Anaconda is to help you install and manage Python packages. When installing and updated packages, the Anaconda software actually has the ability to pull packages from any number of sources. As of mid-2019, there’s one group that provides the best source for packages: conda-forge. So to make that your system’s default, open the command line (after installing Anaconda – if it was open while installing this won’t work) and type the following two commands:

conda config --add channels conda-forge
conda config --set channel_priority strict