Jupyter Notebook: How to Install and Use

Learn about Jupyter Notebook and JupyterLab, the interactive environment that is ideal for Data Science. We’ll explore its advantages over a regular IDE, show you how to install Jupyter Notebook and JupyterLab, and demonstrate its abilities.

Jupyter Lab vs Jupyter Notebook

JupyterLab is a web-based, interactive development environment. It’s best known for its notebooks, but you can also use it to create and edit other files, like code, text files, and markdown files. It also has a file browser, tabs you can arrange side by side, and terminals, so you can experiment and tinker like you would in most IDEs.

JupyterLab is flexible: You can configure and arrange the user interface to support a wide range of data science, scientific computing, and machine learning workflows. It’s also extensible: everyone can write extensions that add new components and integrate with existing ones.

Jupyter runs your code in a kernel: a separate process that executes the code in your notebook. There are kernels for dozens of languages, like Julia, R, and Scala. However, I’ll focus solely on Python in this article.

Jupyter Notebook is the simpler of the two. It’s a REPL-like environment that fuses code, data, and documentation, and it shows one notebook per browser tab. Since version 7, Jupyter Notebook is built from the same components as JupyterLab, so the two look and behave much alike. Both open the same .ipynb files. So in short: JupyterLab is the full browser-based IDE, while Jupyter Notebook is a lighter, document-focused interface. You can install either one, or both, and I’ll show you how in this article.

Advantages of using Jupyter Lab and Notebook

Python application developers often prefer and work with a regular Python IDE like VSCode, which facilitates debugging, unit testing, deployment, and version management. In contrast, (data) scientists and data analysts have a different focus and often prefer a Notebook-style IDE. Let’s look at some of the advantages these notebooks have to offer.

Combine and document your code and results

The biggest advantage of using notebooks is that it allows you to combine three things into one environment:

  1. documentation,
  2. code,
  3. results

All the while offering an interactive environment where you or your fellows can tinker and experiment. The following image perfectly demonstrates this:

A Jupyter notebook combining Markdown, code, output and a chart
A Jupyter notebook combining documentation, output, and code

Interactive exploration

A Notebook allows you to explore your data interactively. While doing so, the Notebook is a log of what you did and how you did it. It’s ideal to use in combination with NumPy and Pandas. So, a Notebook is more geared toward those working with and analyzing data than regular IDEs. However, some IDEs, like VSCode, can open and run Jupyter Notebooks too (see further down this article).

It’s what the others use

Sometimes, it helps to go with the flow. In this case, you’ll notice that many others in data science use Jupyter Notebooks. This has a couple of advantages on its own:

  • It’s easy to exchange and share your work.
  • Many plugins are created by fellow data scientists, specifically targeted at people like you.

How to install Jupyter Notebook and Lab

Before you install anything, you need to make one decision: where does Jupyter live, and where do your packages live? A notebook can only import the packages that are installed in the environment its kernel runs in. If you install Jupyter in one place and pandas in another, import pandas fails with a ModuleNotFoundError. That’s the most common Jupyter problem beginners run into.

There are two good setups:

  1. Install Jupyter inside your project’s virtual environment, next to the packages you use. This is the simplest option, and the one I recommend if you’re starting out.
  2. Install Jupyter once as a global tool, and register each project’s virtual environment as a kernel. This is handy if you have many projects and don’t want a copy of Jupyter in each.

What you shouldn’t do anymore is pip install --user jupyterlab or sudo pip install jupyterlab. Many Linux distributions and Homebrew mark their Python as “externally managed”, and pip refuses to install packages outside a virtual environment there.

Install Jupyter Lab and/or Notebook with Pip

Create and activate a virtual environment for your project first. Then install JupyterLab with the pip install command:

$ python3 -m venv .venv
$ source .venv/bin/activate      # on Windows: .venv\Scripts\activate
(.venv) $ python -m pip install jupyterlab

If you only want Jupyter Notebook, use this instead:

(.venv) $ python -m pip install notebook

Now install the packages you need, like pandas or NumPy, in the same environment. Your notebooks can import them right away.

Install Jupyter with uv

If you use uv to manage your project, you don’t even have to install Jupyter permanently. From your project folder, add the IPython kernel as a development dependency, and start JupyterLab with uv run:

$ uv add --dev ipykernel
$ uv run --with jupyter jupyter lab

uv starts Jupyter with your project’s packages available, so the notebook sees everything you added with uv add. Use jupyter notebook instead of jupyter lab in the last command if you prefer the Notebook interface.

Install Jupyter globally and add your venv as a kernel

For the second setup, install JupyterLab as a tool with uv tool install or pipx. Both give the tool its own isolated environment and put the command on your PATH:

$ uv tool install jupyterlab

or...

$ pipx install jupyterlab

This installs the jupyter-lab command (with a dash). On its own, this Jupyter can only import the packages in its own isolated environment, so you need to tell it about your projects. Activate your project’s virtual environment, install ipykernel in it, and register it as a kernel:

(.venv) $ python -m pip install ipykernel
(.venv) $ python -m ipykernel install --user --name myproject --display-name "Python (myproject)"

The --user here only means the kernel’s description goes in your home folder, where every Jupyter on your system can find it. When you create a notebook, pick “Python (myproject)” as the kernel, and the notebook runs with that project’s packages.

Install JupyterLab with Conda

JupyterLab can be installed with mamba and conda as well. As with pip, install it in the environment you work in, not in conda’s base environment:

$ mamba install -c conda-forge jupyterlab

or...

$ conda install -c conda-forge jupyterlab

Like with Pip, if you only want to install Jupyter Notebook, use this:

$ mamba install -c conda-forge notebook

or...

$ conda install -c conda-forge notebook

Start and explore JupyterLab

How to open Jupyter Lab from the command line

With your virtual environment activated, start JupyterLab with:

$ jupyter lab

(a bunch of log messages will follow)

If you installed JupyterLab as a tool with uv or pipx, the command is jupyter-lab.

How to open Jupyter Notebook from the command line

If you only want to start a Notebook, use this:

$ jupyter notebook

(a bunch of log messages will follow)

Command not found?

If you get an error like “command not found,” don’t panic. If you installed Jupyter in a virtual environment, that environment is probably not active. Activate it and try again.

If you installed it with uv tool install or pipx, the folder with tool commands may not be on your PATH yet. uv warns you about this during the install. Run uv tool update-shell (or pipx ensurepath), then open a new terminal.

Your First Steps in a Notebook

If you start Jupyter Lab or Notebook, it will automatically open your browser. If it didn’t, look in the log messages for a URL starting with http://localhost:8888/ and open it. Once there, create a new Notebook, e.g., by clicking File -> New -> Notebook. If you registered kernels for your projects, Jupyter asks which kernel to use.

I created a new Notebook named ‘First steps’ in the following screenshot. There are a couple of noteworthy things to see:

  • Your input is placed in a ‘cell,’ and each cell is numbered
  • You can access the previous cells by using the In and Out arrays. E.g., Out[3] in the example below gives us the output of the expression in the In[3] cell
  • You can also change the cell type to Markdown; for more on this, see below
  • If you want to apply or execute your cell, press Shift + Enter.
A first notebook in JupyterLab with code cells, their output and Markdown
A simple Jupyter Notebook

Cell types

A dropdown in the toolbar at the top of your notebook allows you to change the cell type. All you need to care about, for now, are the types ‘Code’ and ‘Markdown.’ With a Python kernel, a code cell runs Python.

Python

A Python cell contains Python code. This can be any valid code, so all these are allowed:

Markdown

Markdown is a lightweight markup language for creating formatted text. You can use it to create headers, lists, code snippets, and other things you can think of. For example, you might be familiar with it if you ever created a README.md file on GitHub.

Markdown is great for adding documentation to your notebook. For most, using a Markdown cheat sheet is enough to start quickly.

Formulas

You can enter nice-looking formulas using Markdown as well. Internally, Jupyter uses MathJax to format and display formulas. A formula starts and ends with either a single or a double dollar sign:

  • $ .... $: in-line; the formula is in line with the rest of the current sentence
  • $$ .. $$: display mode; the formula stands out from the rest of the text

Inside, you need to enter a TeX-based equation. If you want to see all the options and play around with such equations, I recommend this website that offers a Tex equation editor.

JupyterLab plugins

JupyterLab calls its plugins extensions. If you click on the puzzle icon at the left of the screen, you open the extension manager, where you can search for extensions and install them. Most extensions are regular Python packages, so you can also install them with pip in the same environment as JupyterLab. There are lots of them, and many add extra visualization capabilities, themes, or integration with other tools.

IPython

Internally, Jupyter Notebooks use a project called IPython. If you tend to use the Python REPL a lot, I recommend you to read our page on IPython since it is an excellent alternative to the regular REPL. I use it a lot personally, and I can’t recommend it enough! For example, it’s worth it just for its terrific auto-completion, and if you are used to Jupyter Notebooks, you’ll feel right at home, obviously.

An IPython session in a terminal with numbered prompts, %timeit and tab completion
IPython in action

Jupyter Notebook in VSCode

If you’re a VSCode fan, like me, you need to check out the Jupyter extension that allows you to create and work with notebooks directly inside a VSCode tab. You don’t need to install JupyterLab for this. Open the command palette with Ctrl + Shift + P (Cmd + Shift + P on macOS) and run Create: New Jupyter Notebook. You can also open any existing .ipynb file.

Next, click Select Kernel in the top right of the notebook and pick your project’s virtual environment, for example .venv. If ipykernel isn’t installed in that environment yet, VSCode offers to install it for you. From then on, the notebook runs with your project’s packages.

File, New File in VSCode, with Jupyter Notebook as one of the choices
Create a new Jupyter Notebook from VSCode

Keep learning

This article is part of a free Python Tutorial. You can browse the tutorial with the navigation buttons at the top and bottom of the article or use the navigation menu. Want to learn more? Here are some great follow-up reads:

  • Learn about NumPy, the foundation of data science in Python.
  • Read how virtual environments work, so you know where your packages end up.
  • It’s always worth visiting the official project website for the latest news and documentation about Jupyter Lab and Jupyter Notebook.

Related articles