Running a Jupyter Notebook is an excellent way for beginners to learn Python in an interactive environment. This tutorial will guide you through setting up and running a Jupyter Notebook on your own computer. The instructions assume you have a basic understanding of operating a computer and can use the command line.
Tutorial Overview
- Introduction to Jupyter Notebook
- Installing Python and Jupyter
- Running a Jupyter Notebook
- A Quick Jupyter Notebook Tour
- Writing Your First Python Code in Jupyter
- Saving and Sharing Your Notebook
1. Introduction to Jupyter Notebook
Jupyter Notebook is an open-source web application that allows you to create and share documents containing live code, equations, visualizations, and narrative text. It’s widely used for data cleaning and transformation, numerical simulation, statistical modeling, data visualization, machine learning, and much more.
2. Installing Python and Jupyter
Prerequisites: Make sure you have Python installed on your system. Python 3.3 or greater, or Python 2.7, is required.
- Step 1: Install Python
- Visit python.org and download the latest version of Python.
- Run the installer, ensuring you check the box that says “Add Python X.X to PATH” during installation.
- Step 2: Install Jupyter using PIP
- Open your command line (Command Prompt on Windows, Terminal on Mac and Linux).
- Enter the following command and press Enter:
pip install notebook
3. Running a Jupyter Notebook
- Step 1: Launch Jupyter Notebook
- Open your command line or terminal.
- Type
jupyter notebook
and press Enter. - Your default web browser will open with the Jupyter Dashboard.
4. A Quick Jupyter Notebook Tour
- The Dashboard: When Jupyter Notebook opens in your browser, you’re greeted with the Dashboard, where you can manage your notebook files.
- Creating a New Notebook: Click on the “New” button on the right and select “Python 3” or “Python 2” to create a new notebook.
- The Notebook Interface: You’ll see a toolbar with buttons and dropdown lists, and below that, an empty cell where you can start typing your code or text.
5. Writing Your First Python Code in Jupyter
- Writing Code: In the empty cell, type the following Python code:
print("Hello, Jupyter!")
- Running the Code: Press
Shift + Enter
or click the “Run” button in the toolbar to execute the code in the cell. You should see “Hello, Jupyter!” printed below the cell.
6. Saving and Sharing Your Notebook
- Saving Your Work: Click on the “Save” button in the toolbar to save your notebook. You can give it a name by clicking on the title at the top.
- Exporting Your Notebook: Go to “File” > “Download as” and choose the format you want to export your notebook to, such as HTML or PDF.
- Sharing Your Notebook: You can share the
.ipynb
file directly with others, or you can use GitHub or other platforms to share your notebooks online.
Conclusion
Congratulations! You’ve successfully set up and run a Jupyter Notebook and written your first Python code. Jupyter Notebooks are powerful tools for learning Python and exploring data science. Experiment with different Python commands, libraries, and explore the rich ecosystem of Jupyter Notebooks. Happy coding!