Packages, Environments, and Versions
Unit ID: M05-U07 Estimated active time: 22-30 minutes
Projects need controlled dependencies
A package can provide importable modules and other files. Third-party packages such as NumPy and pandas are installed separately from Python's standard library.
Different projects may need different package versions. Installing everything into one shared location can create conflicts.
A virtual environment isolates a project
Python's venv tool creates an isolated environment:
python3 -m venv .venv
Activation differs by operating system. The course will provide exact platform instructions only after the runtime is pinned.
Inside an activated environment, install a package with the environment's Python:
python -m pip install pandas
Using python -m pip helps connect the installer with the selected interpreter.
Record versions
python --version
python -m pip --version
python -m pip list
A project may record dependencies in a requirements file. A reproducible environment needs reviewed version constraints, not merely "install the latest".
Notebook kernel mismatch
A notebook may use a different Python environment from the terminal where a package was installed. Inspect the notebook interpreter when imports fail unexpectedly. The first-release browser runtime will pin its own Python and package versions.
Do not install unreviewed packages
Package installation runs third-party software and may bring further dependencies. Use approved package sources, verify the package identity, and avoid commands copied from unknown pages or generated without review.
Course approach
The preferred course experience is an account-free browser notebook with pinned packages. Downloadable notebooks and a documented local environment remain the fallback. Learners should not need to solve environment management before their first Python lesson.
Practice
Without installing anything, write down the difference between:
- the Python interpreter;
- a standard-library module;
- a third-party package;
- a virtual environment; and
- a notebook kernel.
Takeaway
An environment connects an interpreter with installed dependencies. Record versions and verify that the notebook uses the intended environment. Next, we will refactor a long cell by separating concerns.
