Technology Virtual Environments and Dependencies | Python Tutorial

Learn with diagrams, code, systems and practical examples.

</>
TutorialsPythonVirtual Environments and Dependencies
Practical Python · Chapter 28

Virtual Environments and Dependencies

Keep project dependencies isolated and reproducible.

Why this matters

Different projects may need different package versions, and global installs quickly become difficult to reason about.

Start with the idea

A virtual environment provides an isolated Python environment for one project. Activate it before installing project-specific dependencies and record those dependencies in the project configuration.

IdeaUnderstand the purpose
CodeRun the smallest example
PracticeChange it yourself
SubjectVision learning pattern: understand the idea before memorizing syntax.

Small working example

Run this example first. Do not change several things at once; confirm the basic behavior, then experiment.

Python
python -m venv .venv
# activate the environment for your shell
python -m pip install requests
What to notice

The example is intentionally small. Focus on the chapter’s main idea before adding extra syntax or framework code.

Common beginner mistake

Mistake

Installing every package globally and later not knowing which project depends on which version.

Better approach

Use a project-local environment and maintain explicit dependency metadata.

Quick recap

  • Virtual environments isolate dependencies.
  • Use python -m pip for interpreter clarity.
  • Reproducible projects record dependency requirements.

Try it yourself

These are deliberately small. If you can complete them without copying the example, you are ready to continue.

  1. Create a .venv for a sample project.
  2. Install one package and verify it inside the environment.