Sub topic 3
Install JupyterLab, pandas, and matplotlib
This chapter assumes you can run Python 3 from a terminal, know basic Python syntax, and have already created a virtual environment in .venv as in the previous chapter. You will install the three packages that make up the core of the setup, check that they landed in the right place, and learn to recognize the most common installation errors.
What you are installing
Each package has a separate job.
| Package | Role |
|---|---|
| `jupyterlab` | The server and browser interface where you write and run notebooks |
| `pandas` | Tables of data (DataFrames), CSV loading, and summaries |
| `matplotlib` | Plotting, used directly and by pandas' `.plot()` method |
Installing jupyterlab also pulls in its dependencies, including ipykernel, the package that runs your Python code for a notebook. You will use ipykernel again when you register a kernel later in the tutorial.
Install into the active environment
Activate the environment first. Your prompt should show (.venv). Then run the commands below.
python -m venv .venv
source .venv/bin/activate # Windows: .venv\Scripts\activate
python -m pip install --upgrade pip
python -m pip install jupyterlab pandas matplotlibThe first two lines are safe to repeat if the environment already exists. The python -m pip form matters. It runs the pip that belongs to the python currently on your path. A bare pip command can belong to a different Python installation, and the packages would then go somewhere your notebook never looks.
Check the installation
Confirm that the packages import and report their versions.
import sys
import jupyterlab
import pandas as pd
import matplotlib
print("Python: ", sys.executable)
print("JupyterLab:", jupyterlab.__version__)
print("pandas: ", pd.__version__)
print("matplotlib:", matplotlib.__version__)Save this as check_env.py and run python check_env.py. If all three versions print and the Python path is inside .venv, the install worked. You can also run python -m pip list to see everything in the environment, including the dependencies pulled in by JupyterLab.
How the pieces fit together
Because everything lives in one environment, the kernel can import what you installed. Problems appear when the server and the libraries sit in different environments.
Common errors
ModuleNotFoundError: No module named 'pandas'in a notebook. The kernel is running a different Python from the one you installed into. Checksys.executableinside the notebook. The next chapters cover registering and selecting the right kernel.jupyter: command not found. The environment is not active, or JupyterLab went into another Python. Activate.venvand runpython -m pip show jupyterlab.externally-managed-environmenterror. You ranpipagainst a system Python that blocks global installs. Activate your virtual environment and try again. Do not override the protection with--break-system-packages.- Build failures or very slow installs. This usually means an old
pipor an unsupported Python version, so upgradepipfirst. If a package still fails, check that its release supports your Python version.
Exercise
You installed pandas with a bare pip install pandas, but a notebook still raises ModuleNotFoundError. What is the likely cause, and what command form avoids it?
Show answer
The bare pip probably belongs to a different Python installation than the one the notebook kernel uses, so pandas was installed somewhere the kernel cannot see. Running python -m pip install pandas with the project's environment activated installs into the Python you are actually using.
Exercise
Which package installed alongside JupyterLab runs your notebook's Python code, and how can you confirm which Python executable a running notebook uses?
Show answer
ipykernel runs the code. In a notebook cell, run import sys; print(sys.executable) and check that the path points inside your project's .venv folder.