The toolkit on your computer
Last updated
This page runs Python for you, but real data lives on your computer, and so will your projects. In this lesson you'll set up a project with its own virtual environment, install the data tools into it, open JupyterLab, and learn why a notebook sometimes can't find a package you just installed.
By the end of this lesson you can
- Make a project folder with its own virtual environment
- Install the data tools with
pipand record them inrequirements.txt - Open a notebook in JupyterLab or VS Code with the project's Python as its kernel
- Fix a
ModuleNotFoundErrorcaused by the wrong Python
Which Python?
You may already have Python from Simple Python lesson 2.9. If not, follow that lesson's install steps first, then come back. This lesson assumes Python 3.12 or newer is installed.
One computer can hold several Pythons, and the reason most setups go wrong is mixing them up. Step through this first.
.venv folder.A project and its environment
Every project gets its own folder and its own virtual environment: a private copy of Python, in a folder called .venv, with its own packages. Then installing a package for one project can never break another.
Open a terminal (on Windows, PowerShell; on a Mac, Terminal) and type the lines that start with $, one at a time. Don't type the $.
cd Documents mkdir tindahan cd tindahan py -m venv .venv .venv\Scripts\activate (.venv) $ python --version Python 3.14.0
cd ~/Documents mkdir tindahan cd tindahan python3 -m venv .venv source .venv/bin/activate (.venv) $ python --version Python 3.14.0
The last command, activate, switches this terminal to the project's Python. You can tell it worked because the prompt starts with (.venv). Each new terminal starts without it, so run activate again whenever you come back to the project.
If Windows says scripts are disabled when you activate, run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once, answer Y, and try again. It lets scripts you made yourself run, for your account only.
Install the data tools
With the environment active, install the tools this course uses, then save the exact list:
(.venv) $ python -m pip install numpy pandas matplotlib seaborn jupyterlab Collecting numpy ... Successfully installed ... jupyterlab-4... matplotlib-3... numpy-2... pandas-3... seaborn-0... (.venv) $ python -m pip freeze > requirements.txt
python -m pip (instead of just pip) makes sure the packages go into the Python that's running, which is the active environment. It's a small habit that prevents the mistake in step 6.
pip freeze lists every installed package with its exact version, and > saves that list as requirements.txt. Anyone with the project folder (including you, on a new computer) can make the same environment in one line:
py -m venv .venv .venv\Scripts\activate (.venv) $ python -m pip install -r requirements.txt
Keep requirements.txt with the project. Don't copy .venv to another computer or share it: it's big, and it only works on the computer that made it. Make a fresh one from requirements.txt instead.
Open JupyterLab
JupyterLab is the notebook app. Start it from the project folder, with the environment active:
(.venv) $ jupyter lab [I ServerApp] Jupyter Server is running at: [I ServerApp] http://localhost:8888/lab?token=... [I ServerApp] Use Control-C to stop this server.
It opens in your web browser, but it runs on your own computer: localhost means "this computer", and nothing is sent anywhere. The terminal has to stay open while you work; closing it (or pressing Ctrl+C in it) stops JupyterLab.
What you'll see:
- The file browser on the left: your project's folders. Double-click a notebook to open it.
- The launcher: click Python 3 (ipykernel) under Notebook to make a new one. Rename it by right-clicking its tab.
- The toolbar over a notebook: run a cell (▶), stop, restart the kernel, and choose whether a cell is Code or Markdown.
- The kernel name at the top right. It should be the project's Python.
Everything you practised in lessons 1.2 and 1.3 works the same there: Shift+Enter, In [n], Out[n], Markdown cells, Kernel → Restart Kernel and Run All Cells.
Notebooks in VS Code
If you use Visual Studio Code, you can skip JupyterLab: VS Code opens .ipynb files itself, once its Python and Jupyter extensions are installed.
- Open the
tindahanfolder (File → Open Folder). - Make a file called
01-first-look.ipynb. VS Code shows it as a notebook. - Click Select Kernel at the top right, then Python Environments, and choose the one in
.venv.
The notebook works the same way. Pick whichever app you like: the notebook files are the same, and either can open the other's.
This page's notebooks also run Python, so you can check which one with code. Run these: on your own computer the version will be the one in your .venv.
Wrong way: installed, but not found
The most common setup problem: you install pandas, open a notebook, type import pandas, and get ModuleNotFoundError: No module named 'pandas'. You did install it. But you installed it into one Python, and the notebook's kernel is another (step 1 showed exactly this).
Run the cells below to see the error for yourself. This page's notebook doesn't have seaborn yet, so import seaborn fails the same way.
-
This page’s notebook has Python’s standard library, NumPy and pandas, but not seaborn yet: it arrives with the charts in Stage 7. So here,
import seabornfails exactly the wayimport pandasdoes on a computer where pandas isn’t installed in the notebook’s Python. -
-
To fix it on your computer, check two things:
- Which kernel is the notebook using? In JupyterLab it's the name at the top right; in VS Code, the kernel button. Choose the project's
.venv. - Where did
pipinstall? Activate the environment first, and usepython -m pip install, so packages go into the Python you're running.
If JupyterLab doesn't list your .venv as a kernel, start JupyterLab from the activated environment (step 4), or run python -m pip install ipykernel in it.
Check what you learned
Sources
Every example on this page was run with Python 3.14, and its output and error messages are copied from it. These pages cover the same ground in more depth.
- Python Packaging User Guide: Install packages in a virtual environment using pip and venv: making, activating and installing into a virtual environment
- The Python Standard Library: venv: what a virtual environment is
- Python Packaging User Guide: Requirements files: pip freeze and pip install -r
- JupyterLab: Installation: installing and starting JupyterLab
- VS Code: Jupyter Notebooks in VS Code: opening notebooks and choosing a kernel