Reading preferences
Concept

Packages and Python Environments

Isolate dependencies and understand how project metadata and installation fit together.

python, packages, venv, pip, dependencies, pyproject

Keep projects separate

A Python module is an importable unit; a package organises modules under a common import name. An installable distribution may provide one or more import packages, and its distribution name can differ from an import name. A virtual environment gives a project its own installed dependencies. It is not a security sandbox.

Python illustration

The following is a prepared local-project workflow, not code executed by Intuvo. Start in a project directory with Python and pip installed:

python3 -m venv .venv
.venv/bin/python -m pip --version
.venv/bin/python -m pip install .

On Windows, the interpreter is commonly .venv\Scripts\python.exe; use that path instead. The last command installs the current project's distribution and its declared dependencies into the chosen environment. It needs a correctly configured project and may require network access.

See the reasoning

Follow the example one step at a time

Trace the local project's environment and dependency installation. This is a prepared teaching demonstration, not live code execution.

Choose a project

project/
  pyproject.toml
  study_notes/

The project metadata describes a distribution; the source package must actually exist.

Describe a project

An illustrative pyproject.toml for a project that actually contains the package study_notes could be:

[build-system]
requires = ["setuptools"]
build-backend = "setuptools.build_meta"

[project]
name = "study-notes"
version = "0.1.0"
requires-python = ">=3.10"
dependencies = ["requests>=2.31"]

The build backend must be able to find the project's actual source files. The example dependency is illustrative, not needed by Intuvo. Use python -m pip install some-package only after checking the source and project requirements. Dependencies can pull in other dependencies; pin or lock versions using an appropriate project workflow for reproducibility. Do not commit environment directories or credentials. Package installation and imports can execute third-party code, so review what you trust.

Reflect on the concept

Four fixed questions to reinforce the reasoning. Answers are not saved or scored.

1. What is a Python package?
2. Why create a virtual environment?
3. Why use python -m pip?
4. What can project.dependencies declare in pyproject.toml?

References and further reading