Skip to main content

Adding Python 3 to Jupyter Notebook

These instructions are for people who have Anaconda installed already with only Python 2, or for some other reason want to create a new Python 3 environment to use for the workshops.

If you have Python installed, but you don’t have an Anaconda installation, you should be able to install Anaconda for Python 3 and use Jupyter Notebooks through the Anaconda installation. When installed this way, Python 3 should show up under the New menu once you start Jupyter Notebooks.

Add an Environment to Jupyter Notebooks

Jupyter Notebooks can be started with different Python environments. But you have to register an environment with Jupyter Notebooks before it will show up in the options when you click the button to create a new notebook.

Create a New Conda Environment

On a Mac, open a Terminal from Applications > Utilities. On Windows, open Anaconda Navigator and start an Anaconda prompt.

We’re going to make a new environment called p3workshop. Do this by typing:

conda create -n p3workshop python=3.7 ipykernel jupyter anaconda

This will prompt you to install some additional packages. Enter “y” when asked to proceed. It will take a while because it’s installing all of the standard Anaconda packages into the new environment.

Activate the Environment

Next, activate the new environment. There’s a command at the end of the creation script that shows you how to do this. It should look like:

source activate p3workshop

or

conda activate p3workshop

 

Register the Environment with IPython

Jupyter Notebook is built on IPython. We need to tell IPython about the new environment we just made so Jupyter Notebooks can include it as an option.

ipython kernel install --name p3workshop --user

Now close the Terminal or Prompt window you’ve been using.

Start Jupyter Notebook

Now, start Jupyter Notebook by opening it from the Anaconda Navigator program or by typing

jupyter notebook

at the command line. Check to see that p36workshop now shows up in the list of options when you create a new notebook. You do not need to have the p3workshop environment active when you start Jupyter Notebook.

Installing Packages

If you install packages from a Jupyter Notebook using p3workshop, the packages will install in this new conda environment you’ve created. If you want to install packages from the command line into this environment, remember to activate the environment first before using conda install or pip install.