Pynions

Jupyter Notebook Setup That Survives Restart and Run All

Set up Jupyter Notebook 7.6.5 with pip or uv, bind a venv kernel, and fix hidden state. Tested commands, study data, and when marimo or VS Code wins instead.

Updated 13 min read
Laptop screen showing lines of code in a text editor

A Jupyter notebook is a .ipynb file that mixes runnable code, its output, and Markdown notes, edited in the browser through Jupyter Notebook or JupyterLab and executed by a separate kernel process. The current releases are Notebook 7.6.5 and JupyterLab 4.6.6, both shipped on 6 November 2026.

The catch is reproducibility. When researchers re-ran 863,878 notebooks from GitHub, only 4.03% reproduced their saved results. This guide covers setup with pip and uv, per-project kernels, and the exact commands that keep your notebooks runnable, all tested on Python 3.15.2.

Key Takeaways

  • Install with pip install notebook (Notebook 7) or pip install jupyterlab, or skip installs entirely with uv run --with jupyter jupyter lab inside a project.
  • Notebook 7 is built on JupyterLab components and Jupyter Server. Classic Notebook 6 gets maintenance and security fixes only.
  • Register each project's virtual environment as its own kernel with python -m ipykernel install --user --name <name>. A wrong kernel is the usual cause of ModuleNotFoundError in a notebook.
  • Hidden state is the real failure mode: of 863,878 re-run GitHub notebooks, only 24.11% ran without errors, and 36.36% of notebooks with a clear execution order had cells run out of order.
  • Run every notebook headless with jupyter nbconvert --execute before you share it, strip outputs from git with nbstripout, and switch to marimo when you want the tool to enforce execution order for you.

What Is a Jupyter Notebook?

The Jupyter Notebook documentation describes three parts. The web application is where you write and run code.

Kernels are separate processes that execute that code and send results back. The notebook document (.ipynb) stores your inputs, outputs, narrative text, and images in one file.

Cells come in three types: code, Markdown, and raw. You run a code cell with Shift-Enter, and the output appears directly under it. That loop of write, run, inspect, adjust is why data work moved into notebooks.

Jupyter is language-agnostic. The project supports over 40 languages, including Python, R, Julia, and Scala, because the kernel is a swappable process. The Jupyter Notebook repo traces the app back to IPython: the language-agnostic notebook split out of IPython in 2015, in what the project calls The Big Split.

Project Jupyter homepage with the Jupyter logo and programming language icons

Is Jupyter Notebook an IDE?

Not in the full sense. Jupyter Notebook is a document-centric editor with a REPL attached. JupyterLab adds a file browser, terminals, and multi-panel layouts, and the project itself calls it a web-based interactive development environment.

Jupyter also has no interpreter of its own. It runs whichever Python environment the selected kernel points to.

The top answer on a 2026 r/Python thread about the real use case for Jupyter puts the use case plainly: "The main thing Jupyter gives you is interactive, cell-by-cell execution. You write a bit of code, run it, see the output immediately, tweak it, run again." (u/PavelRossinsky, 2026)

Why Jupyter Notebook Matters in 2027

The .ipynb format is still the interchange file for exploratory Python. VS Code, Google Colab, and marimo's converter all read it, so a notebook you write today opens in each of them.

The tooling also changed under the name. Notebook 7, announced on 26 July 2023, brought JupyterLab's visual debugger, real-time collaboration (through the jupyter-collaboration extension), table of contents, and dark theme into the classic document view. If your mental model of Jupyter Notebook is the 2018 interface, it is out of date.

How Jupyter Notebook Works: Install, Launch, Pick a Kernel

Three decisions define a working setup: which interface you launch, which tool installs it, and which environment the kernel runs. Get the third one wrong and imports fail even though the package is installed.

Install Jupyter Notebook With pip

Notebook 7.6.5 requires Python 3.10 or newer. Create a virtual environment per project and install it there:

Shell
python3 -m venv .venv
source .venv/bin/activate
pip install notebook==7.6.5
jupyter notebook --version

The last line prints 7.6.5. On Windows, activate with .venv\Scripts\activate instead. Start the app with jupyter notebook; it opens a browser tab with a file dashboard.

Prefer the multi-panel interface? Jupyter's install page gives the JupyterLab equivalent:

Shell
pip install jupyterlab==4.6.6
jupyter lab

When both packages are installed, each app detects the other, so you can move between the document view and JupyterLab on the same files.

Run Jupyter With uv Instead

If your project already uses uv, you do not need to add Jupyter to the project at all. The uv Jupyter guide runs JupyterLab in an isolated layer on top of the project's environment:

Shell
uv run --with jupyter jupyter lab

The server starts at http://localhost:8888/lab, and notebooks can import every dependency in your pyproject.toml. In our test on a fresh uv project, that command resolved Notebook 7.6.5 and JupyterLab 4.6.6 on Python 3.15.2. For why uv replaced pip in many Python projects, see uv vs pip.

Register a Virtual Environment as a Kernel

A kernel is just a JSON spec that says which Python executable to launch. When Jupyter lives in one environment and your project in another, you register the project's environment explicitly, as the IPython kernel docs describe:

Shell
python3 -m venv .venv
source .venv/bin/activate
pip install ipykernel==7.4.0 pandas==3.1.1
python -m ipykernel install --user --name sales-report --display-name "Python (sales-report)"
jupyter kernelspec list

The list now shows a sales-report entry under your user's Jupyter data directory, next to the default python3 kernel. Pick "Python (sales-report)" from the kernel menu and imports resolve against that .venv. The --name value is internal; --display-name is the label you see, and reusing a name overwrites the old spec.

uv users get the same result with uv add --dev ipykernel followed by uv run ipython kernel install --user --env VIRTUAL_ENV $(pwd)/.venv --name=project, per the uv guide.

Your First Cells

With the kernel selected, a first cell can load data and show a result inline. The last expression in a cell is displayed automatically:

Python
import pandas as pd

sales = pd.DataFrame({
    "region": ["north", "south", "north", "west"],
    "revenue": [120, 95, 180, 60],
})
sales.groupby("region")["revenue"].sum()

With pandas 3.1.1 the cell renders:

Text
region
north    300
south     95
west      60
Name: revenue, dtype: int64

To add a package from inside a notebook, use the %pip magic, which runs pip within the current kernel. A bare !pip runs whatever pip is first on the shell's path, which may not be the kernel's environment. For a full analysis workflow on top of this, the Python data analysis guide picks up where this section stops.

Notebook 7 vs JupyterLab 4 vs Classic Notebook 6

The three interfaces open the same .ipynb files, because they share the notebook document format. The differences are layout, extension support, and maintenance status.

Interface

Version (Nov 2026)

Layout

Status

Jupyter Notebook 7

7.6.5

One document per tab

Active, built on JupyterLab components

JupyterLab 4

4.6.6

Panels, terminals, file browser

Active

Classic Notebook 6

6.5.x branch

One document per tab

Maintenance and security only

Pick Notebook 7 if you want one notebook per browser tab and nothing else on screen. Pick JupyterLab if you keep a terminal, a CSV preview, and two notebooks open at once.

Stay on Classic Notebook 6 only for a legacy extension you cannot replace. The project says extensions written for Notebook 5 or Classic Notebook 6 are not compatible with Notebook 7, which is the one real upgrade cost.

The Reproducibility Problem: What 1.16 Million Notebooks Show

The clearest numbers on notebook quality come from the MSR 2019 study by Pimentel, Murta, Braganholo, and Freire. The team collected 1,159,166 notebooks from 264,023 GitHub repositories and tried to re-run the ones with an unambiguous execution order.

Finding

Share

Notebooks that ran without errors

24.11% of 863,878

Notebooks that reproduced their saved results

4.03%

Unambiguous-order notebooks with out-of-order cells

36.36%

Notebook runs that hit NameError

14.53%

Notebook runs that hit FileNotFoundError or IOError

12.59%

Re-run notebooks that declared dependencies

13.72%

The data is from 2019, but the execution model it describes still applies. You run cells one at a time in whatever order you choose, a cell can run many times, and the file keeps only the latest output of each.

How Hidden State Happens

Say you define tax_rate = 0.21 in a cell, use it below, then delete the cell while tidying up. The kernel still holds tax_rate, so every later cell keeps working and the saved output looks fine. The file no longer contains the code that produced it.

You can reproduce the failure headlessly. Save this as demo.py in the py:percent format, where each # %% marks a cell:

Python
# %%
prices = [19.99, 5.49, 3.50]

# %%
total = sum(prices) * (1 + tax_rate)
print(f"Total: {total:.2f}")

Convert it to a notebook with jupytext and execute it top to bottom with nbconvert, exactly as a colleague would after cloning your repo:

Shell
pip install jupytext==1.19.7
jupytext --to notebook demo.py
jupyter nbconvert --to notebook --execute demo.ipynb

The run stops with NameError: name 'tax_rate' is not defined, the same exception the study hit in 14.53% of its notebook runs. Your interactive session never showed it.

Why "Just Run All Cells" Is Only Half the Fix

On X, Jean-Francois Puget (@JFPuget, January 2026) argued that "The cure is simple: always execute all cells in a notebook in order." He is right about the habit, and the paper's authors recommend the same thing: re-run notebooks before committing to restore the execution counters.

The habit fails when nobody enforces it. Restarting fixes hidden state, but it does nothing for the 86% of re-run notebooks that declared no dependencies, or for absolute paths to data on one laptop. The next section turns the habit into checks.

A Reproducibility Toolkit for Jupyter Notebooks

Each step below is a command you can put in a Makefile or CI job. Together they catch hidden state, missing dependencies, and noisy diffs before anyone else opens the file.

Restart and Run All Before You Save

In JupyterLab the command is "Restart Kernel and Run All Cells…" (notebook:restart-run-all). In Notebook 7 the Kernel menu restarts the process, and 0,0 in command mode does the same, per the Notebook docs.

Make it a reflex before every commit. If the notebook fails after a restart, it was already broken; you just had not seen it.

Execute Notebooks Headless in CI

jupyter nbconvert --execute runs a notebook in a fresh kernel and exits non-zero on the first error, so it works as a test. Fix the demo by restoring the missing cell:

Python
# %%
prices = [19.99, 5.49, 3.50]

# %%
tax_rate = 0.21

# %%
total = sum(prices) * (1 + tax_rate)
print(f"Total: {total:.2f}")

Then convert and execute in place, which writes fresh outputs and sequential execution counts back into the file:

Shell
jupytext --to notebook demo.py
jupyter nbconvert --to notebook --execute --inplace demo.ipynb

The last cell now prints Total: 35.07. Add the same nbconvert --execute line to CI for every notebook you share.

Check Execution Order With nbformat

Execution counts tell you how a notebook was run. This short script, using nbformat (installed alongside Notebook), flags never-run cells, out-of-order runs, and gaps that point to re-runs or deleted cells:

Python
import sys

import nbformat

nb = nbformat.read(sys.argv[1], as_version=4)
counts = [c.execution_count for c in nb.cells if c.cell_type == "code"]
ran = [n for n in counts if n is not None]

if None in counts:
    print("Never-run code cells:", counts.count(None))
if ran != sorted(ran):
    print("Out of order:", counts)
elif ran != list(range(1, len(ran) + 1)):
    print("Gaps in the count (re-runs or deleted cells):", counts)
else:
    print("Clean top-to-bottom run:", counts)

Save it as check_order.py and run python check_order.py demo.ipynb on the notebook nbconvert just executed. It prints Clean top-to-bottom run: [1, 2, 3]. A notebook you ran by hand in a different order prints the "Out of order" line instead.

Strip Outputs From Git With nbstripout

An .ipynb file is JSON that holds code and outputs together, so small edits produce large diffs. In the same r/Python thread, u/spartanOrk described the cost: "git commits get enormous, you cannot commit only the code in them without the graphics, unless you strip the graphics first."

nbstripout does the stripping as a git filter, so outputs stay in your file on disk but never reach the commit:

Shell
pip install nbstripout==0.9.2
nbstripout --install
git config --get filter.nbstripout.clean

The last command prints the filter command nbstripout registered for the repository. Use nbstripout --install --global --attributes=~/.config/git/attributes to apply it to every repo on your machine.

Pair Notebooks With Plain Python Files

jupytext can keep a .py twin of each notebook in sync. The .py file holds only inputs, so it diffs and reviews like normal code:

Shell
jupytext --set-formats ipynb,py:percent demo.ipynb

That writes demo.py next to the notebook. After editing the .py file in your editor, jupytext --sync demo.py updates the .ipynb, per the jupytext docs.

Export for People Who Do Not Run Code

jupyter nbconvert --to html demo.ipynb writes a static demo.html that anyone can open. nbconvert also exports to PDF, LaTeX, Markdown, slides, and an executable script. HTML needs nothing beyond nbconvert itself, which makes it the low-friction default.

If you build dashboards for non-technical readers, a Streamlit app beats a notebook export as the delivery format. For more tested Python workflows like this one, the Pynions newsletter sends new guides.

Jupyter vs VS Code vs Colab vs marimo

The alternatives split on two questions: where the code runs, and whether the tool enforces execution order. All four read .ipynb files.

Tool

Runs on

File format

Execution order

Price

Jupyter Notebook / JupyterLab

Your machine or server

.ipynb JSON

Any order, your discipline

Free, BSD-3-Clause

VS Code + Jupyter extension

Your machine

.ipynb JSON

Any order

Free

Google Colab

Google's hosted runtime

.ipynb JSON

Any order

Free tier, resources not guaranteed

marimo

Your machine

.py file

Reactive, dependency-ordered

Free, Apache-2.0

VS Code Notebooks

VS Code opens .ipynb files natively through the Jupyter extension and adds a Variable Explorer, Data Viewer, and a debugger. It needs an environment with ipykernel installed, chosen from the kernel picker in the top right, per the VS Code docs.

Choose it when your notebook sits inside a codebase you already edit in VS Code. The execution model is still Jupyter's, so hidden state works the same way.

Google Colab

Colab is a hosted Jupyter Notebook service that needs no setup and offers free access to GPUs and TPUs. Google's Colab FAQ also states that resources are "not guaranteed and not unlimited".

Use Colab for a quick GPU experiment or for teaching. The same FAQ advises including cells that install and load any custom libraries your notebook needs, so put those installs at the top.

marimo

marimo stores each notebook as a plain Python file and runs reactively: when you run a cell, marimo runs every cell that reads the variables it defines. Delete a cell and marimo deletes its variables, which the marimo docs say eliminates hidden state.

You can try it on an existing notebook in one command, from the Coming from Jupyter guide:

Shell
pip install marimo==0.26.0
marimo convert demo.ipynb -o demo_marimo.py
python demo_marimo.py

The script prints Total: 35.07.

marimo homepage showing the pip install marimo command and a notebook preview

Open demo_marimo.py and the last cell is a function with the signature def _(prices, tax_rate):, so the dependency the deleted cell broke is now explicit in the code.

The trade-off is compatibility. marimo does not support IPython magics or ! shell commands, and some marimo UI elements do not work after exporting back to .ipynb. On r/Python, 2026 posts such as a modern-stack thread list marimo next to uv, Ruff, and Polars. That matches who adopts it: developers who want notebooks to behave like code.

Common Jupyter Notebook Mistakes to Avoid

Installing Packages Into the Wrong Environment

!pip install pandas in a cell can install into a different Python than the kernel uses, and the next import fails. Use %pip install, or register the project's .venv as a kernel and select it.

Deleting a Cell Whose Variables You Still Use

The kernel keeps every variable until it restarts, so the notebook looks fine until someone else runs it. Restart and run all after any cleanup pass.

Committing Outputs and Secrets

Outputs end up in the JSON, including printed API keys and embedded images. Install nbstripout as a git filter before your first commit, not after the repo is already heavy.

Hard-Coding Paths to Your Laptop

In the Pimentel study, 12.59% of re-run notebooks stopped on FileNotFoundError or IOError, which the authors tie to absolute paths and data missing from the repository. Keep data paths relative to the repo, or read them from an environment variable.

Shipping Logic That Only Lives in a Notebook

Daniel Lee's LinkedIn post "don't be a Jupyter Notebook Engineer" makes the point for data teams: structure projects like a software engineer, with scripts, modules, and tests, and keep API keys in environment variables. Keep notebooks for exploring and explaining, and keep the pipeline in code you can test.

Frequently Asked Questions

Sources

Related Articles