Skip to content

Latest commit

 

History

History
70 lines (43 loc) · 2.43 KB

jupyter_cheat_sheet.md

File metadata and controls

70 lines (43 loc) · 2.43 KB

Jupyter Cheat Sheet

We use Jupyter Notebook for several assignments with Python. This app allows us to write, run and store Python code in one interactive file that opens in a web browser.

We installed Jupyter in a Python virtual environment using these instructions:

Install virtualenv and Jupyter

We created the virtual environment in a folder named jupyter_work and installed Jupyter there.

All of that is done ONLY ONCE.

To launch Jupyter Notebook

cd into the folder (e.g. jupyter_work) where you set that up.

Activate the virtual environment (at the command prompt).

MacOS:

source env/bin/activate

Windows:

env\Scripts\activate.bat

Start Jupyter Notebook (at the command prompt):

jupyter notebook

Everything else happens in your web browser. Choose the file you want to open from the list there. If the file isn’t there yet, you can use the Mac Finder or Windows File Explorer to drag it into the folder in the usual way.

Jupyter in the browser

Above: The directory you were in when you launched Jupyter Notebook appears in your web browser.

To quit Jupyter Notebook

This is a two-step process. First you need to save and close your work in the web browser.

  • To save your work, Command-S.
  • To exit from the notebook, open the Jupyter File menu and select “Close and Halt.”
  • Click LOGOUT in the upper right corner.

Then, in the Terminal, press Control-C — NOT Command.

Still in Terminal — type y (lowercase) and press Enter/Return.

Quit from your virtual environment

Deactivate the virtual environment (at the command prompt):

deactivate

Handy Jupyter Notebook commands

  • Hold the Shift key and press Enter/Return to run the code in the current cell in the notebook.
  • Press a to insert a cell above the current cell
  • Press b to insert a cell below the current cell
  • Press d twice to delete the current cell
  • Press m to convert the current cell from code to Markdown (this allows you to write text notes in the notebook using Markdown); you can use # to write Python comments in your code, but sometimes you want to paste in an explanation or even a URL, and Markdown makes that nicer.
  • Press Command S (Mac) or Control S (Win) to save your work