Anaconda is a free Python distribution for data analysis and scientific computing. It has its own package manager, conda. The distribution includes more than 200 Python packages, which makes it very convenient. For casual users, the Miniconda distribution may be the better choice. Miniconda contains the conda package manager and Python. The technical editors use Anaconda, and so do I. But don't worry, I will describe in this book alternative installation instructions for readers who are not using Anaconda. In this recipe, we will install Anaconda and Miniconda and create a virtual environment.
The procedures to install Anaconda and Miniconda are similar. Obviously, Anaconda requires more disk space. Follow the instructions on the Anaconda website at http://conda.pydata.org/docs/install/quick.html (retrieved Mar 2016). First, you have to download the appropriate installer for your operating system and Python version. Sometimes, you can choose between a GUI and a command-line installer. I used the Python 3.4 installer, although my system Python version is v2.7. This is possible because Anaconda comes with its own Python. On my machine, the Anaconda installer created an anaconda
directory in my home directory and required about 900 MB. The Miniconda installer installs a miniconda
directory in your home directory.
Now that Anaconda or Miniconda is installed, list the packages with the following command:
$ conda list
For reproducibility, it is good to know that we can export packages:
$ conda list --export
The preceding command prints packages and versions on the screen, which you can save in a file. You can install these packages with the following command:
$ conda create -n ch1env --file <export file>
This command also creates an environment named
ch1env
.The following command creates a simple
testenv
environment:$ conda create --name testenv python=3
On Linux and Mac OS X, switch to this environment with the following command:
$ source activate testenv
On Windows, we don't need
source
. The syntax to switch back is similar:$ [source] deactivate
The following command prints export information for the environment in the YAML (explained in the following section) format:
$ conda env export -n testenv
To remove the environment, type the following (note that even after removing, the name of the environment still exists in
~/.conda/environments.txt
):$ conda remove -n testenv --all
Search for a package as follows:
$ conda search numpy
In this example, we searched for the NumPy package. If NumPy is already present, Anaconda shows an asterisk in the output at the corresponding entry.
Update the distribution as follows:
$ conda update conda
The .condarc
configuration file follows the YAML syntax.
Note
YAML is a human-readable configuration file format with the extension .yaml
or .yml
. YAML was initially released in 2011, with the latest release in 2009. The YAML homepage is at http://yaml.org/ (retrieved July 2015).
You can find a sample configuration file at http://conda.pydata.org/docs/install/sample-condarc.html (retrieved July 2015). The related documentation is at http://conda.pydata.org/docs/install/config.html (retrieved July 2015).
Martins, L. Felipe (November 2014). IPython Notebook Essentials (1st Edition.). Packt Publishing. p. 190. ISBN 1783988347
The conda user cheat sheet at http://conda.pydata.org/docs/_downloads/conda-cheatsheet.pdf (retrieved July 2015)