Sub topic 4
Start JupyterLab and find your way around
This chapter assumes you have finished the previous chapter. You need an active virtual environment with jupyterlab, pandas, and matplotlib installed. You should also be comfortable running commands in a terminal.
What `jupyter lab` actually does
Running jupyter lab starts a local web server on your machine. The server serves the JupyterLab interface to your browser. It also manages the kernels, which are the separate processes that run your code.
Start it from your project folder, with the virtual environment active:
jupyter labThe terminal prints several lines, and then it stays busy. That is expected. The terminal is now the server's log window, so leave it open while you work. Closing it, or pressing Ctrl+C twice, stops the server.
Most of the time the browser opens by itself. If it does not, copy the URL from the terminal output. It looks like this:
http://localhost:8888/lab?token=3f9a...The token part is a one-time secret that proves the request comes from you. The security chapter covers it in detail. For now, treat the full URL as a password and do not paste it into chats or tickets.
Why the starting folder matters
JupyterLab uses the folder where you ran the command as its root. The file browser cannot show anything above that folder. If you start it from your home directory, your project is buried among unrelated files. If you start it from inside the project, the layout is clean.
A good habit is to change into the project folder first, then activate the environment, then launch:
cd my-analysis
source .venv/bin/activate
jupyter labOn Windows, activate with .venv\Scripts\activate instead.
If port 8888 is already in use, for example by a second server, JupyterLab picks the next free port, such as 8889. Always read the URL it prints instead of assuming 8888.
The main parts of the interface
When JupyterLab opens, you see four areas.
| Area | Location | What it does |
|---|---|---|
| Menu bar | Top | File, Edit, View, Run, Kernel, and Settings menus |
| Left sidebar | Left edge | File browser, running terminals and kernels, table of contents, extensions |
| Main work area | Center | Tabs for notebooks, text files, terminals, and the Launcher |
| Status bar | Bottom | Kernel state, and whether the notebook is in command or edit mode |
The Launcher is the tab of large tiles that appears at first. It lets you create a new notebook, open a terminal, or create a text file. If you close it, click the + button above the file browser to bring it back.
The tiles under Notebook list the available kernels. A kernel built from your environment is the one you want. The next chapters explain how to register one, so a plain Python 3 tile is fine for now.
Create and save your first notebook
- In the file browser, click the New Folder icon and name it
notebooks. Double-click it to enter. - Click +, then choose a Python tile under Notebook.
- Rename the file with File > Rename Notebook, for example to
01-explore.ipynb. - Type
print("hello")in the first cell and press Shift+Enter.
The output appears under the cell. The file is saved as JSON with the .ipynb extension, and JupyterLab autosaves it regularly.
Common errors
jupyter: command not found. The environment is not active, or JupyterLab was installed in a different environment. Activate the right one and runpython -m jupyter lab.- Files are missing from the browser. You started the server in a different folder. Stop it and restart it from the project folder.
- The page loads but asks for a password or token. You opened
localhost:8888without the token. Use the full URL from the terminal. - Closing the browser tab does not stop the server. The server and its kernels keep running. Use File > Shut Down, or Ctrl+C in the terminal.
Exercise
You run jupyter lab from your home directory and the file browser shows none of your project files. What is the cause, and how do you fix it?
Show answer
The server's root is the folder where you launched it, and your project is not inside the part it can show. Stop the server with Ctrl+C, change into the project folder, activate the environment, and run jupyter lab again.