Site

Tools — Python Development Toolchain

Tutorial 2.0  •  Python / Learn

2.0 What This Teaches

This tutorial covers the tools you need for Python development:

2.1 Installing Python

Download the latest Python 3 release from https://www.python.org. During installation on Windows, check "Add Python to PATH" so you can run python from any terminal. Verify the installation:
python --version
python3 --version
On macOS and Linux, the system may ship an older Python. Install a current version via Homebrew (brew install python) or pyenv for managing multiple versions.

2.2 Virtual Environments

A virtual environment is an isolated copy of Python with its own package directory. Installing packages into a venv keeps them separate from other projects and the system Python. Always use a venv for real projects.
# Create a virtual environment in .venv/
python -m venv .venv

# Activate it (Linux/macOS)
source .venv/bin/activate

# Activate it (Windows PowerShell)
.venv\Scripts\Activate.ps1

# Your prompt changes to show (.venv)
# Now python and pip use the venv

# Deactivate when done
deactivate
The .venv folder is not committed to source control - add it to .gitignore.

2.3 pip Package Manager

pip installs packages from PyPI (the Python Package Index at pypi.org). With your venv active:
pip install requests          # install a package
pip install requests==2.31.0  # install specific version
pip install -r requirements.txt  # install from list
pip list                      # show installed packages
pip freeze > requirements.txt # save current packages to file
pip uninstall requests        # remove a package
requirements.txt lists your project's dependencies so others can reproduce your environment with pip install -r requirements.txt.

2.4 Project Layout

A minimal Python project looks like this:
my_project/
    .venv/              # virtual environment (not in git)
    src/
        my_project/
            __init__.py
            main.py
    tests/
        test_main.py
    requirements.txt
    README.md
The __init__.py file marks a directory as a Python package. It can be empty. The src/ layout prevents accidental imports from the project root during testing.

2.5 pyproject.toml

Modern Python projects use pyproject.toml instead of setup.py. It declares metadata and dependencies in a standard format:
[project]
name = "my_project"
version = "0.1.0"
requires-python = ">=3.11"
dependencies = [
    "requests>=2.31",
]
Build tools like hatch, flit, or poetry read this file. For simple scripts, requirements.txt is sufficient.

2.6 IDE Options

IDENotes
VS Code + Python extensionFree, cross-platform, excellent venv integration, Pylance type checking
PyCharm CommunityFree, Python-specific IDE with strong refactoring and debugging
Jupyter NotebookInteractive notebook format; ideal for data exploration and teaching
VS Code with the Python extension handles venv activation, debugging, and linting automatically once you select an interpreter.

2.7 Exercise

Exercise Create a new project folder called myapp. Create a virtual environment in it. Activate it. Install the requests library. Capture the installed packages to requirements.txt with pip freeze. Deactivate the venv. Then recreate it fresh and verify you can restore packages from requirements.txt.

2.8 Common Mistakes

Forgetting to activate the venv

Running pip install without activating the venv installs packages into the system Python, not your project's venv. Your script then fails to import them when run inside the venv. Always activate before installing or running.

Not pinning versions in requirements.txt

pip freeze captures exact versions (e.g., requests==2.31.0). Writing only requests without a version means a different machine may install a newer, incompatible version. Pin versions for reproducible builds.

Committing .venv to source control

The .venv folder is large, platform-specific, and regeneratable. Add .venv/ to .gitignore. Teammates recreate it with python -m venv .venv && pip install -r requirements.txt.

2.9 Key Terms

TermMeaning
venvVirtual environment: isolated Python with its own packages
pipPython package installer; installs from PyPI
PyPIPython Package Index - the public package repository at pypi.org
requirements.txtList of pinned package versions for reproducible installs
pyproject.tomlModern project metadata and dependency declaration format
__init__.pyFile that marks a directory as a Python package
interpreterThe python executable that reads and runs .py files