Sub topic 3
Install JupyterLab, pandas, and matplotlib
This chapter assumes you can run Python 3 from a terminal, know basic pip usage, and have already created and activated a virtual environment for your project (covered in the previous chapter). Everything below happens inside that active environment.
What you are installing
Three packages make up the core of the setup.
| Package | Role | Pulls in |
|---|---|---|
| `jupyterlab` | The browser interface and the server that hosts it | `jupyter-server`, `notebook` components, `ipykernel`, `nbconvert` and many more |
| `pandas` | Tables (DataFrames) and CSV loading | `numpy`, `python-dateutil`, `pytz` and others |
| `matplotlib` | Plotting | `numpy`, `pillow`, `kiwisolver`, `cycler` and others |
pip resolves and installs these dependencies for you. The exact list depends on the versions available, which is one reason the later chapter on recording dependencies matters.
Confirm you are in the right environment
The most common installation error is installing into the wrong Python. Check before you install.
which python # Windows: where python
python -c "import sys; print(sys.prefix)"The path should point inside your project's .venv folder. If it points to a system location such as /usr/bin or C:\Python312, activate the environment first.
Install the packages
Upgrade pip, then install all three packages in one command so pip can resolve their shared dependencies (such as numpy) together.
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 only needed if you have not yet created the environment. The last line downloads and installs the packages.
What happens during installation
All files land in the site-packages folder of the virtual environment. Nothing is written to the system Python, which is the point of isolating the project.
Verify the installation
Do not assume success. Check that each tool is present and comes from the environment.
jupyter lab --version
python -c "import pandas, matplotlib; print(pandas.__version__, matplotlib.__version__)"
python -m pip listThe first command prints the JupyterLab version. The second prints two version numbers, or raises ModuleNotFoundError if a package is missing. The third lists everything installed, which is useful when you later freeze dependencies.
You can also confirm that the jupyter command resolves inside the environment.
which jupyter # Windows: where jupyterThe path should end in .venv/bin/jupyter (or .venv\Scripts\jupyter.exe on Windows).
Common errors and fixes
| Symptom | Likely cause | Fix |
|---|---|---|
| `jupyter: command not found` | Environment not activated, or install failed | Activate `.venv`, then rerun the install |
| `ModuleNotFoundError: No module named 'pandas'` inside a notebook | The notebook uses a different Python than the one you installed into | See the kernels chapter and select the correct kernel |
| `jupyter` runs but is a different version than expected | An older global install shadows the environment's copy | Check `which jupyter`; reactivate the environment |
| `externally-managed-environment` error | You are running `pip` against a system Python that blocks installs | Create and activate a virtual environment, then retry |
| Build errors or very long compile steps | No prebuilt wheel exists for your Python version or platform | Use a Python version with published wheels, usually a currently supported release, or upgrade `pip` |
| SSL or proxy errors | Corporate network or proxy | Configure `pip` with your proxy settings or an internal package index |
Optional: install extras later
You do not need to install everything now. Add packages as the analysis requires them.
python -m pip install seaborn scipy openpyxlEach addition changes the environment, so remember to refresh your recorded dependencies afterward. The reproducibility chapter shows how.
Version pinning and upgrades
By default pip install fetches the newest compatible release. That is convenient for a fresh project but can change behavior between machines and dates. To install a specific version:
python -m pip install "pandas==2.2.*"To upgrade a package later:
python -m pip install --upgrade pandasUpgrading in the middle of a project can change results or break code, so do it deliberately and rerun your notebooks afterward.
Check that the stack works together
A short smoke test confirms that pandas and matplotlib work without opening a notebook. It uses the non-interactive Agg backend so it also runs on machines without a display.
import matplotlib
matplotlib.use("Agg")
import matplotlib.pyplot as plt
import pandas as pd
df = pd.DataFrame({"x": [1, 2, 3], "y": [2, 4, 8]})
df.plot(x="x", y="y")
plt.savefig("smoke_test.png")
print("OK", df.shape)Save it as smoke_test.py and run python smoke_test.py. It should print OK (3, 2) and create smoke_test.png. You can delete the image afterward.
Summary of the workflow
- Confirm the active interpreter points into
.venv. - Upgrade
pip. - Install
jupyterlab,pandas, andmatplotlibin one command. - Verify versions and executable locations.
- Run a smoke test.
Exercise
You installed pandas with pip install pandas, but a notebook raises ModuleNotFoundError: No module named 'pandas'. In a terminal with the environment active, python -c "import pandas" works. What is the most likely cause, and where do you look next?
Show answer
The notebook is running on a kernel that uses a different Python interpreter than the one in your virtual environment. The terminal check passes because it uses the environment's Python. Next, check which kernel the notebook has selected and register the environment as a kernel, as covered in the kernels chapter.
Exercise
Why is python -m pip install jupyterlab pandas matplotlib preferred over three separate pip install commands, and why is python -m pip preferred over pip?
Show answer
A single command lets pip resolve shared dependencies such as numpy once and pick mutually compatible versions. Using python -m pip ensures the pip belongs to the same interpreter as python, so packages go into the active environment and not a different Python installation.