Skip to content

getting_started_jupyter

The most common way to interact with the IPython kernel is through a Jupyter web interface like JupyterLab or the classic Jupyter Notebook. Let’s see how to start and perform basic operations.

Open your terminal or Anaconda Prompt, navigate to the directory where you want to store your notebooks, and type:

jupyter lab

This command starts the JupyterLab server and should automatically open a new tab in your default web browser pointing to the JupyterLab interface (usually at http://localhost:8888/lab).

The JupyterLab interface typically shows a file browser on the left, a main work area in the center, and potentially other panes for running terminals, kernels, etc.

If you prefer the classic interface, use:

jupyter notebook

This will open the classic Notebook dashboard in your browser, showing a file list from the directory where you started the command.

In JupyterLab, use the ’+’ button in the file browser or the ‘Launcher’ tab to create a new notebook, typically selecting the ‘Python 3 (ipykernel)’ kernel.

In the classic Notebook dashboard, click the ‘New’ button and select ‘Python 3’.

This opens a new browser tab containing an empty notebook file (.ipynb).

A notebook consists of cells. Cells are containers for code or text. The two primary cell types are:

  • Code Cells: Contain code to be executed by the kernel (e.g., Python code). They have an In [ ]: prompt.
  • Markdown Cells: Contain text formatted using Markdown syntax, allowing for rich text, headings, lists, links, images, and equations. They are used for documentation and narrative.

You can change the type of the currently selected cell using the dropdown menu in the toolbar or keyboard shortcuts (e.g., Esc to enter Command Mode, then m for Markdown or y for Code).

To execute the code in a code cell:

  • Select the cell.
  • Press Shift + Enter (executes the cell and selects/creates the cell below).
  • Press Ctrl + Enter (executes the cell and keeps it selected).
  • Press Alt + Enter (executes the cell and inserts a new cell below).

When you execute a code cell:

  1. The code is sent to the IPython kernel.
  2. The kernel executes the code.
  3. Any output (from print statements, or the value of the last expression in the cell) is displayed below the cell.
  4. The prompt number In [ ]: changes to In [*]: while running, and then to In [N]: (where N is the execution count) upon completion.
# Example Code Cell
import time
print("Starting calculation...")
time.sleep(2)
result = 10 + 5
print("Calculation finished.")
result # The value of the last expression is displayed as output
# Output after execution:
# Starting calculation...
# Calculation finished.
# Out[N]: 15

Enter text using Markdown syntax in a Markdown cell. Execute the cell (Shift+Enter) to render it into formatted text.

# Example Markdown Cell (Raw Text)
# My Analysis Plan
This notebook explores the dataset `data.csv`.
1. Load the data
2. Perform initial cleaning
3. Generate visualizations
See [Markdown Cheatsheet](https://www.markdownguide.org/cheat-sheet/) for syntax.
# Rendered Output after Shift+Enter:
# (Formatted text with heading, list, and link)

Notebooks are saved automatically at intervals, but you can manually save using the floppy disk icon, Ctrl + S, or Cmd + S.

To shut down the Jupyter server, go back to the terminal where you started jupyter lab or jupyter notebook and press Ctrl + C twice.

This covers the basics of launching Jupyter and working with notebook cells. The next sections will delve into specific IPython features available within this environment.