Skip to content

Installing and Configuring Anaconda and Jupyter Notebooks

Simon Wiles edited this page Dec 3, 2019 · 2 revisions

In many of our Python workshops we will be use Jupyter Notebooks as our Integrated Development Environment (IDE), and the Anaconda distribution of Python.

Anaconda

Anaconda is a software application that packages together different Python versions and a package manager. There are other options out there, like using your distribution's Python version, or pyenv, but we won't be covering the setup for those. Therefore, the first thing to do is to download and install the Anaconda Navigator graphical installer for Python 3.5 (or higher).

Jupyter Notebooks

The Jupyter Notebook App is a server-client application that allows editing and running “notebook“ documents via a web browser [...] In addition to displaying/editing/running notebook documents, the Jupyter Notebook App has a “Dashboard” (Notebook Dashboard), a “control panel” showing local files and allowing to open notebook documents or shutting down their kernels.

In Jupyter, a kernel is the engine in which commands are run. In our case, the engine will be in Python, specifically, the IPython kernel.

Jupyter let's you write and evaluate code at a granular level without re-running scripts constantly and using a lot of print debugging. It also allows mixing in Markdown and HTML within your notebook, and so is a great way of presenting code and data analysis.

For getting started, you should go to the official Jupyter documentation, the starter guide, or take a look at how to run code, or other interesting notebooks. There are even video tutorials available.

Virtualenvs

In the Python world, a virtualenv, virtual environment, or just environment, is a way of managing isolated environments so each project can have its own dependencies without conflicts with other projects.

A Virtual Environment is a tool to keep the dependencies required by different projects in separate places, by creating virtual Python environments for them. It solves the “Project X depends on version 1.x but, Project Y needs 4.x” dilemma, and keeps your global site-packages directory clean and manageable.

Anaconda has its own environment and package manager (conda) -- it lets you easily set your Python version, and comes with many of the standard packages used in scientific computing. It also provides the concept of channels so you can easily install packages that are maintained by other people. We will be covering the instructions for setting up your Python environment using Anaconda.

Setting up Jupyter using Anaconda in the command line

To set up an environment, in your shell or terminal, run ($ means a shell command):

$ conda create -n name_of_your_environment python=x.y package1 package2

This creates an environment named name_of_your_environment, where the Python version is specified to x.y, and installs the packages lib1 and lib2 into the environment.

For example:

$ conda create -n data python=3.5 jupyter requests

Installs jupyter and requests in a data virtualenv using Python 3.5.

After you create the environment, run

$ source activate name_of_your_environment

Or

$ activate name_of_your_environment

Depending on whether you are on OSX or Windows to activate the environment.

Once you have a virtual environment running, just install jupyter and run jupyter notebook from the location where you want to store your notebook.

$ jupyter notebook

And go to http://localhost:8888/ in your browser.

If you need to install packages from other channels, just add -c channel_name to the install command:

$ conda install -n name_of_your_environment -c channel_name package_maintained_by_someone_else

Often times, we will be using the channel conda-forge for more up-to-date or missing packages from the official Anaconda repository.

Setting up Jupyter using Anaconda Navigator

First, launch the Anaconda-Navigator interface, go to "Environments," and create a new one with Python 3.5 (or higher) and click on it.

Environment creation

Go to channels and add a new one called conda-forge, then click on "Update channels."

Channels

Now go to the "Installed" packages and select "Not installed." Look for "jupyter" in the "Search Packages" box and mark it to install. Repeat the process for any other package you need, such as "requests" for example. Then click on "Applyl," and you should see a list of packages before installing the them. Click "OK."

Packages

Once installation is finished, click on the green triangle and select "Open with Jupyter Notebook." A terminal window should popup. It's loading Jupyter. After a few seconds you should see the main interface of Jupyter showing the current directory contents.

Launching Jupyter

Navigate to where you want your notebooks stored, and then click on "New" and select "Python 3.5". Now you should be ready to start writing Python code in a new and clean notebook.

Launching a Notebook

Final remarks

Now you should have all you need to start coding in Python with Anaconda and Jupyter Notebook. We still recommend you to have your code control versioned, preferably with a tool like git, to ease history revision and to avoid accidental code loss.

Happy coding!