Overview
Jupyter Notebook is a powerful tool for interactive computing that allows you to create and share documents containing live code, equations, visualizations, and narrative text. In this lesson, we’ll cover how to install Jupyter Notebook and get started with using it for Python programming and data analysis tasks.
Learning Objectives
- Install Jupyter Notebook on your local machine.
- Understand the basic features and interface of Jupyter Notebook.
- Learn how to create, run, and save Jupyter Notebook documents.
Installing Jupyter Notebook
To install Jupyter Notebook, you typically need Python installed on your system. Here are the steps to install Jupyter Notebook using pip
, assuming Python is already installed:
- Open a Terminal or Command Prompt:
- On Windows, you can use Command Prompt or PowerShell.
- On macOS or Linux, use Terminal.
- Install Jupyter Notebook:
- Run the following command to install Jupyter Notebook:
pip install jupyterlab
This command installs JupyterLab, which is an enhanced version of Jupyter Notebook. Alternatively, you can install the classic Jupyter Notebook by running:pip install notebook
- Run the following command to install Jupyter Notebook:
- Verify Installation:
- After installation, you can verify it by typing
jupyter notebook
in the terminal/command prompt. This command should start the Jupyter Notebook server and open it in your default web browser.
- After installation, you can verify it by typing
Getting Started with Jupyter Notebook
Once Jupyter Notebook is installed, follow these steps to get started:
- Start Jupyter Notebook:
- Open a terminal/command prompt and type:
jupyter notebook
- This will start the Jupyter Notebook server and automatically open the interface in your default web browser.
- Open a terminal/command prompt and type:
- Interface Overview:
- Jupyter Notebook interface consists of:
- Dashboard: Shows files and folders in the current directory.
- Notebook Dashboard: Lists running notebooks and allows you to open, rename, or delete them.
- Notebook Editor: Where you create and edit your notebooks with code cells and markdown cells.
- Jupyter Notebook interface consists of:
- Creating a New Notebook:
- Click on
New
button on the top right corner and selectPython 3
(or any other kernel you need). - This will open a new notebook document.
- Click on
- Working with Cells:
- Jupyter Notebook uses cells for writing and executing code or text. There are two main types of cells:
- Code Cells: Execute Python code.
- Markdown Cells: Write formatted text using Markdown syntax.
- Jupyter Notebook uses cells for writing and executing code or text. There are two main types of cells:
- Executing Code:
- Enter Python code in a code cell and press
Shift + Enter
to execute it. - Output (if any) will be displayed directly below the code cell.
- Enter Python code in a code cell and press
- Saving and Closing:
- To save your work, click on the
Save
button or pressCtrl + S
(Cmd + S
on macOS). - To close a notebook, click on
File
>Close and Halt
from the menu, or simply close the browser tab.
- To save your work, click on the
Example: Creating a Simple Notebook
Here’s an example of creating and using a simple Jupyter Notebook:
Start Jupyter Notebook from terminal:
jupyter notebook
In the Jupyter interface, click New
> Python 3
to create a new notebook.
In the first code cell, type and execute the following Python code:
# Example code cell
print("Hello, Jupyter!")
Press Shift + Enter
to execute the cell. The output "Hello, Jupyter!"
should appear below the cell.
Create more cells as needed and explore the features of Jupyter Notebook.
Conclusion
Jupyter Notebook is a versatile tool for interactive computing and data analysis with Python. By installing Jupyter Notebook, understanding its interface, and learning how to create, run, and save notebooks, you can efficiently work on Python projects, conduct data analysis, and collaborate with others by sharing your notebooks.