Python (Jupyter) Notebooks

Tue, Nov 19, 2019

Installing HomeBrew

The first step to getting setup with Python notebooks is to install Homebrew. Homebrew is a program that you install via the command line (Terminal program on your Mac) and it will allow you to install other software easily with just a few commands. Homebrew is called a package installer.

https://brew.sh/

When you visit the Homebrew website, copy and paste the command into your Terminal. Generally, you never want to do this with any website you don’t completely trust.

When installing Homebrew, it will ask you for your computer’s admin password. This is the only time Homebrew asks for this info. After you install it, all other software is sandboxed in special locations to prevent malware.

Xcode Commandline Tools

Command line tools Xcode

During its installation, Homebrew might ask about Xcode Commandline Tools software. Simply follow the prompts to agree to the user agreement to continue.

Installing Python3 on a Mac

If you’re using a Mac, the next step is to install Python3, which also installs a separate Python-specific package installer called pip3. We will use this in this lesson.

brew install python3

Install Python

This will install Python3 on your computer. (Macs already come with an older version of Python. This won’t replace it, but install it in a unique location so that both can coexist.)

Install VirtualEnv

The next step is to install a piece of software called Virtual Enviornment. This allows you to create a sandbox program on your computer where you can install specific Python packages that are unique to any given project, without having to install them on your whole computer. This is common practice.

pip3 install virtualenv 

Now that we have Virtual Environment installed, we should create a folder and navigate to that folder using the terminal. This next part of the tutorial will have you create a folder on your Desktop.

mkdir ~/Desktop/python_notebook
cd ~/Desktop/python_notebook
virtualenv .

This will create a Virtual Environment in this folder. To activate the Virtual Environment, type:

source bin/activate

This will change your prompt, indicated you’re inside the Virtual Environment.

Installing Jupyter Notebook

Next, let’s install the software we will need to run our notebook.

pip3 install jupyter pandas matplotlib

This will install three pieces of software and their dependencies: Jupyter Notebooks, Pandas data library, and a visualization library called MatPlotLib.

Next, let’s launch our Python Notebook:

jupyter notebook

This should launch Jupyter Notebook in your browser window.

Jupyter Notebook in a browser window

Click on the new button, and select Python3 from notebooks.

From this page, you can input commands in each cell, and press shift + return to run a command.