How to Set Up and Use Jupyter Notebooks Locally

Tuesday, November 19, 2024 by TommyA
How to Set Up and Use Jupyter Notebooks Locally

How to Set Up and Use Jupyter Notebooks Locally

Introduction

Hello! Tommy here, and today I’m thrilled to introduce you to the world of Jupyter Notebooks. Whether you’re a total beginner curious about coding or someone exploring how to use notebooks for data analysis, this tutorial is for you. I'll guide you through setting up Jupyter Notebook on your local computer step-by-step. No prior technical experience? No worries—I’ve got you covered with clear instructions and simple explanations.

By the end of this guide, you’ll know how to install Jupyter Notebook, start it on your computer, and create your first notebook to run Python code. Ready to unleash the power of Jupyter? Let’s dive in and make it easy and fun! 🚀

Step 1: Install Python

Jupyter Notebooks run on Python, so the first thing we need to do is install Python on your computer.

  1. Download Python:
    • Go to the official Python website.
    • Click the Download Python button. The website will automatically detect the right version for your operating system.
      python downloads page
      Python download page
  2. Install Python:
    • Open the downloaded file to start the installation.
    • During installation, make sure to check the box that says “Add Python to PATH”—this is important for everything to work properly.
    • Follow the on-screen instructions to complete the installation.

Once Python is installed, you’re ready to install Jupyter Notebook.

Step 2: Install Jupyter Notebook

Jupyter Notebook is a tool that comes as a Python package. We’ll install it using a tool called pip, which is included with Python.

  1. Open Command Prompt or Terminal:

    • On Windows, search for Command Prompt in the Start menu.
    • On macOS/Linux, open the Terminal application.
  2. Install Jupyter Notebook:

    • Type the following command into Command Prompt or Terminal and press Enter:

      pip install notebook
      
    • Wait for a few moments while Jupyter Notebook is downloaded and installed.

Now that Jupyter is installed, let’s learn how to open it.

Step 3: Launch Jupyter Notebook

We’re now ready to launch Jupyter Notebook and open its interface in your web browser.

  1. Navigate to Your Folder:

    • In Command Prompt or Terminal, type cd followed by the path to the folder where you want to save your work. For example:

      cd Documents
      

    This step tells Jupyter where to save your files.

Start Jupyter Notebook:

  • Type this command in the terminal/command prompt and press Enter:
    jupyter notebook
    
  • Your default web browser will open, showing the Jupyter Notebook interface.
    This is how mine looks like from the directory I entered the command:
    Jupyter server
    Jupyter server

If the browser doesn’t open automatically, copy the link shown in Command Prompt or Terminal and paste it into your browser.

Fallback urls
Jupyter fallback urls

Step 4: Create Your First Notebook

Now that Jupyter is running, let’s create your very first notebook.

  1. In the Jupyter interface, click the “New” button on the right side of the screen.
  2. From the dropdown menu, select “Python 3”.
  3. A new notebook will appear in the file list with the default name Untitled.ipynb.
    New Notebook
    New Notebook
  4. To rename the file, right-click on Untitled.ipynb and select Rename from the menu.
  5. Enter a new name for the file and ensure it ends with .ipynb (e.g., MyFirstNotebook.ipynb).
  6. Double-click the renamed file to open it. You’ll be redirected to a new page where you can interact with the kernel and start coding in your notebook.

When the new tab opens, you might see a pop-up box titled "Select Kernel" (like the one in the image). If this happens, simply leave Python 3 as the selected kernel and click Select. This ensures your notebook is ready to run Python code.

Select kernel
Select kernel

Let’s try running some Python code!

Step 5: Write and Run Your First Python Code

Jupyter Notebooks are interactive, meaning you can write and execute code one piece at a time.

  1. In the empty box (called a “cell”), type the following Python code:

    print("Hello, Jupyter!")
    
  2. Press Shift + Enter on your keyboard to run the code.

  3. You’ll see the output below the cell—“Hello, Jupyter!”

    Print code
    Print code

Step 6: Save and Close Your Notebook

Once you’re done working on your notebook, it’s essential to save your progress and close everything properly.

  1. Save Your Work:
    • To save your notebook, go to the top menu and click on File > Save Notebook. Alternatively, you can press Command + S (macOS) or Ctrl + S (Windows) to save quickly.
  2. Close the Notebook:
    • To close the notebook, go to File > Close and Shut Down Notebook. This ensures the notebook stops running in the background.
  3. Stop Jupyter Notebook:
    • After closing the notebook, go back to your Command Prompt or Terminal.
    • Press Ctrl + C and type Y when prompted to confirm shutting down the Jupyter Notebook server.
      Shutdown kernel
      Shutdown kernel

Conclusion

Congratulations! You’ve successfully set up Python and Jupyter Notebook on your local computer, created your first notebook, and even wrote and ran some Python code. Along the way, you learned how to rename your notebook, select the appropriate kernel, and save your work. Jupyter Notebook is a fantastic tool that combines code, visuals, and narrative in a single interface, making it ideal for learning and experimenting.

This guide is just the beginning of what you can achieve with Jupyter. Whether you’re planning to explore data analysis, create visualizations, or dive into machine learning, Jupyter Notebook provides a beginner-friendly environment to bring your ideas to life.

Now that you’ve taken this first step, remember that the only limit is your curiosity. Keep experimenting, keep learning, and most importantly—have fun as you embark on your coding journey! 🎉

Next Steps?

  1. Learn More Python:

    • Explore tutorials on Python basics to build your coding skills.
  2. Use Python Libraries:

    • Try out libraries like numpy for math, pandas for data, and matplotlib for charts. Install them using:

      pip install numpy pandas matplotlib

  3. Customize Your Notebooks:

  • Add notes and descriptions in your notebooks using Markdown.
  1. Share Your Work:
  • Save and share your .ipynb files or upload them to platforms like GitHub.
  1. Keep Experimenting:
  • Use Jupyter Notebooks to explore data, create visualizations, or even build small projects.

Upcoming AI Hackathons and Events