Artificial Intelligence / Learning Tools

Jupyter Notebook

A notebook lets you combine runnable code, notes, and results in one interactive document.

What is Jupyter Notebook?

Jupyter Notebook is an interactive environment for creating and running computational notebooks. A notebook is made of cells: some contain code, and others can contain written explanations. When you run a code cell, its result appears in the notebook.

ride-fare.ipynb Python kernel ready
Text
Calculate the total fare

Multiply the number of rides by the fare per ride.

▶
rides = 3
fare = 12
rides * fare
Code runs in the kernel
Out36
A notebook keeps instructions, code, and results together. Run a code cell, and its kernel produces an output that appears below it.

A kernel is the process that runs the notebook’s code and remembers values between cells. Jupyter supports Python and many other languages through different kernels.

A small example

One code cell can calculate a value:

rides = 3
fare_per_ride = 12
total = rides * fare_per_ride
total

When you run the cell, the notebook displays 36 below it. A Markdown cell could explain that the example multiplies the number of rides by the fare per ride.

Why use it for Python and AI?

Notebooks are useful when learning or exploring because you can run a small piece of code, see its result, and add an explanation beside it. People use them to inspect data, make charts, and experiment with machine-learning models one step at a time.

Jupyter itself is not an AI model. It is a workspace where you can write and run code that uses Python libraries, data, or AI tools.

Install and run Jupyter from Terminal

For a Python notebook, you need Python, a virtual environment for the project, and Jupyter installed in that environment. These steps are for macOS and assume you are using Python’s built-in venv tool. First, open Terminal and create a folder named jupyter-learning for your notebook files:

mkdir -p ~/jupyter-learning
cd ~/jupyter-learning
  1. Check that Python 3 is installed: run python3 --version. Terminal should print a version number. If the command is not found, install Python 3 before continuing.
  2. Create a virtual environment: run python3 -m venv .venv. This creates an isolated environment in a folder named .venv in your project.
  3. Activate it: run source .venv/bin/activate. You should see (.venv) at the start of your Terminal prompt.
  4. Install Jupyter: run python -m pip install jupyter. You only need to install it once in this environment.
  5. Start the notebook server: run jupyter notebook.

Here are the commands together:

cd ~/jupyter-learning
python3 --version
python3 -m venv .venv
source .venv/bin/activate
python -m pip install jupyter
jupyter notebook

Jupyter prints a local link in Terminal and may open it in your browser. Open your .ipynb file from the file list, then run a cell with Shift + Enter. The notebook server and Python code run on your computer. To stop the server, return to Terminal and press Control + C.

When you return to the project later, activate the environment and start Jupyter again:

cd ~/jupyter-learning
source .venv/bin/activate
jupyter notebook

Try a notebook

Download this starter notebook into your jupyter-learning folder, then open it in Jupyter Notebook. If your browser saves downloads to a different folder, move the file into ~/jupyter-learning. It has a few short cells for trying Python, importing a built-in module, and seeing how cell outputs work.

Download the starter notebook

Open a downloaded notebook locally

Make sure the downloaded .ipynb file is in ~/jupyter-learning, the folder where you created .venv. Open Terminal and run:

cd ~/jupyter-learning
source .venv/bin/activate
jupyter notebook

When Jupyter opens in your browser, click the notebook’s filename in the file list. The notebook and its code will run locally on your computer.

What is Google Colab?

Google Colab is an online service for creating and running Jupyter notebooks in a web browser. You can write Python code in notebook cells and run it on a computer hosted by Google, so you do not need to install Jupyter on your own computer to use Colab.

To open an existing .ipynb notebook, go to Google Colab and choose File → Upload notebook. You can also save notebooks in Google Drive and share them with others. Colab runs code in a temporary session, so save or download your work to keep it. To try the starter notebook above in Colab, download it and upload the file there.

Where does the name Jupyter come from?

Jupyter is a name drawn from the programming languages the project originally supported: Julia, Python, and R. It is not a formal acronym with a separate full phrase for each letter.

Why does the file end in .ipynb?

.ipynb comes from the earlier name IPython Notebook. The notebook project grew out of IPython and kept this file extension when it became Project Jupyter.

An .ipynb file is a JSON-based document. It stores notebook cells, notes, outputs, and metadata, so the code and its displayed results can live together in one file.

Learn more