Sub topic 4
Start JupyterLab and find your way around
This chapter assumes you have finished the previous one. That means a project folder with an activated virtual environment (.venv) that has jupyterlab, pandas, and matplotlib installed. You should be comfortable running commands in a terminal and know what a working directory is. Kernel registration and cell editing get their own chapters. Here you will start the server, understand what is running, and learn the layout of the interface.
What happens when you run `jupyter lab`
Running jupyter lab does not open a desktop application. It starts a local web server, and your browser connects to it. Three pieces are involved:
- The server is a Python process started from your terminal. It serves the web interface and reads and writes files on disk.
- The browser is the interface. It displays notebooks and sends your actions to the server.
- Kernels are separate processes that execute your code. The server starts one for each open notebook.
The server and the kernels are different processes. The server decides which files you can see. The kernel decides which Python and which packages run your code.
This split explains many beginner problems. If a package imports in your terminal but not in the notebook, the kernel is using a different Python than your terminal. Fixing that is the subject of the kernels chapter.
Start the server from the right place
Open a terminal in your project folder and activate the environment:
cd my-analysis
source .venv/bin/activate # Windows: .venv\Scripts\activate
jupyter labThe terminal prints log lines. Two matter most:
- A line with a URL such as
http://localhost:8888/lab?token=.... Thetokenis a one-time password for this server session. - A note that the browser is being opened. If it does not open, copy the full URL, token included, into your browser.
Leave this terminal open. The server runs in it, and closing the window stops the server and every kernel.
The launch directory is your file root
JupyterLab uses the directory where you ran the command as its root. The file browser cannot navigate above it. If you start the server in your home folder, you see your whole home folder. If you start it in my-analysis, you see only that project. Starting in the project folder is usually what you want. Relative paths like data/sales.csv also resolve against the notebook's own folder, so a consistent layout prevents "file not found" errors.
You can override the root without changing directories:
jupyter lab --notebook-dir=/path/to/my-analysisUseful launch options
| Option | Effect | When to use it |
|---|---|---|
| `--no-browser` | Starts the server without opening a browser tab | Remote machines, or when you want to paste the URL into a specific browser |
| `--port=8890` | Listens on port 8890 instead of 8888 | Running two servers, or when 8888 is taken |
| `--notebook-dir=PATH` | Sets the file root | Launching from a different directory |
| `--ServerApp.open_browser=False` | Same as `--no-browser`, in config-style form | Scripts and shared launch commands |
Options combine freely:
jupyter lab --no-browser --port=8890Reading the server log
The log shows what the server is doing, and it is the first place to look when something fails. A typical start prints the Python executable path, the extensions that loaded, and the URLs. Later, kernel starts and file saves appear as lines. Errors from your notebook code appear in the notebook itself, but kernel crashes and port problems show up here.
To see which servers are running on your machine and their URLs, open a second terminal and run:
jupyter server listThis is useful when you have lost the original URL and token. Running it from a terminal where the environment is active matters, because it queries the jupyter that is first on your PATH.
Find your way around the interface
The JupyterLab window has five regions.
Menu bar
The top menu holds File, Edit, View, Run, Kernel, Tabs, Settings, and Help. Three menus are worth knowing now:
File > Shut Downstops the whole server from the browser.Kernelcontrols the kernel of the active notebook. Restart and shutdown options are here.View > Show Hidden Filesreveals dotfiles such as.venvand.gitignorein the file browser.
Left sidebar
The icon strip on the far left switches between panels:
- File Browser shows files under the root. Use the
+button for a new Launcher, the folder button for a new folder, and the upload button for files from your computer. Double-clicking a.csvopens a table viewer. Double-clicking an.ipynbopens a notebook. - Running Terminals and Kernels lists every open kernel and terminal, with a shutdown button for each. Closing a notebook tab does not stop its kernel. The kernel keeps running, and its memory stays allocated, until you shut it down here.
- Table of Contents builds an outline from Markdown headings in the active notebook.
- Extension Manager manages optional add-ons. Skip it for now.
Press Ctrl+B (Cmd+B on macOS) to collapse or expand the sidebar and gain screen width.
Launcher
The Launcher is a tab with tiles. The Notebook section shows one tile per registered kernel, such as Python 3 (ipykernel). The Console section opens a command-line-style session on a kernel. The Other section includes Terminal, Text File, and Markdown File. Click the + button at the top of the file browser to open a new Launcher at any time.
The Terminal tile gives you a shell inside the browser, started in the file root. Whether the virtual environment is active in it depends on how you launched the server. A terminal started from the server process usually inherits the activated environment, but check with which python (where python on Windows).
Main work area
Notebooks, text files, terminals, and data viewers open as tabs here. You can drag a tab to the edge of the area to split the view, for example to put a notebook beside a CSV preview. This is one of the main advantages of JupyterLab over the older single-document interface.
Status bar and command palette
The status bar at the bottom shows the kernel state and whether the notebook is in command or edit mode. The kernel name in the top right of a notebook shows which kernel is attached, and a filled or empty circle next to it shows busy or idle.
The command palette is Ctrl+Shift+C (Cmd+Shift+C on macOS). It searches every action by name, so you can find a command without memorizing menu locations.
Create your first notebook
- In the file browser, open the
notebooksfolder, or create it with the folder button. - Click the
+button, then choose the Python tile under Notebook. - Rename the file with right-click and
Rename. The defaultUntitled.ipynbis easy to lose track of. - In the first cell, enter
import sys; sys.executableand pressShift+Enter.
The output is the path to the Python that runs your code. It should point inside your .venv folder. If it does not, the kernel is using another interpreter. The kernels chapter explains how to fix this.
Stop the server cleanly
You have three options:
- In the server terminal, press
Ctrl+C. It asksShutdown this Jupyter server (y/[n])?, so typeyand press Enter. PressingCtrl+Ca second time also confirms. - In the browser, choose
File > Shut Down. - From another terminal, run
jupyter server stop 8888, replacing the port with the one in your URL.
Save your notebooks first. Shutting down kills the kernels and discards any variables in memory.
Common errors
| Symptom | Likely cause | Fix |
|---|---|---|
| `jupyter: command not found` | The virtual environment is not active, or JupyterLab was installed elsewhere | Activate `.venv`, then run `python -m jupyterlab` as a fallback |
| Browser does not open | Headless machine, or no default browser configured | Copy the URL with the token from the log |
| Server starts on 8889 or 8890 | Another server is already using 8888 | Use the URL printed in the log, or stop the old server |
| Page asks for a password or token | You opened `localhost:8888` without the token | Use the full URL from the log or from `jupyter server list` |
| Files missing from the file browser | The server was launched in a different directory | Stop it and relaunch from the project folder |
| Port is in use and the server will not start | A fixed `--port` value is taken | Choose another port, or stop the process holding it |
Exercise
You launched jupyter lab from your home directory, and the file browser shows hundreds of unrelated files. How do you make JupyterLab show only the project folder my-analysis, and how do you check from a notebook that its code runs in the project's virtual environment?
Show answer
Shut down the server (Ctrl+C, then y), cd into my-analysis, activate .venv, and run jupyter lab again. You can also keep your current directory and run jupyter lab --notebook-dir=my-analysis. In a notebook cell, run import sys; sys.executable. The printed path should end inside my-analysis/.venv.
Exercise
You closed a notebook tab, but your computer's memory use did not drop. Where in the JupyterLab interface do you find and stop the kernel that is still running?
Show answer
Open the Running Terminals and Kernels panel in the left sidebar. It lists the open kernels. Click the shutdown button next to the notebook's kernel. Closing a tab only closes the view, not the kernel process.