Skip to content
Learn Netverks

Lesson

Step 22/36 61% through track

packages-venv

Packages and venv

Last reviewed May 28, 2026 Content v20260528
Track mode
server_script
Means
Server runner
Reading
~1 min
Level
intermediate

This lesson

This lesson teaches Packages and venv: the syntax, patterns, and safety habits you need before advancing in Python.

Virtual environments isolate dependencies—production deploys pin versions in requirements.txt or poetry.lock.

You will apply Packages and venv in contexts like: Scripts, Django/FastAPI apps, notebooks, and glue code between systems.

Write Python 3 in the editor and click Run on server—the dev runner executes your script with print() for output; stdlib only in playground snippets (LEARNING_RUNNER_ENABLED=true).

When you can explain the previous lesson's ideas without copying starter code.

A package groups modules under a directory (with __init__.py or namespace package rules). A venv is an isolated Python environment with its own site-packages—essential per-project dependency hygiene.

Layout example

myapp/
  pyproject.toml
  src/myapp/
    __init__.py
    main.py

Creating a venv (local)

python3 -m venv .venv
source .venv/bin/activate   # macOS/Linux
pip install -r requirements.txt

The playground runs single files—practice full package layout on your machine before the Django track.

Important interview questions and answers

  1. Q: venv vs system Python?
    A: venv isolates dependencies per project—avoids breaking system tools or other projects.
  2. Q: __init__.py purpose?
    A: Marks a directory as a package and can run package initialization code.

Self-check

  1. What command creates a venv?
  2. Why not pip install globally for every project?

Tip: One venv per project—python3 -m venv .venv before pip install.

Interview prep

Why venv?

Isolates dependencies per project—Project A and B can require different Django versions.

__init__.py role?

Marks package directory; can run package initialization on import.

Interview tip Lesson completion confidence

Can you explain this lesson in 30 seconds without reading notes?

Not saved yet.

Playground

Runs on the configured server runner (dev: npm run runner with LEARNING_RUNNER_ENABLED=true). Output appears below the editor.

Check yourself

Multiple choice — immediate feedback.

Discussion

Past discussion is visible to everyone. Only logged-in users can post comments and replies.

Starter discussion topics

  • __init__.py?
  • Package layout?

Sign up or log in to post comments and sync lesson progress across devices.

No discussion yet. Be the first to ask a question.

Jump