█
LastWrite
  • > Curriculum
  • > Pricing
  • > For Educators
  • > About
  • > Contact
Log InGet Started

Questions, concerns, bug reports, or suggestions? We read every message, write to us at [email protected].

More ways to reach us →
LastWrite

Structured computer science lessons for aspiring developers and security professionals.

[email protected]

(201) 785-7951

Mon–Fri, 9 AM–5 PM EST

Learn

  • Curriculum
  • Pricing

Company

  • About
  • For Educators & Schools
  • Contact Us

Legal

  • Terms of Service
  • Privacy Policy
© 2026 LastWrite. All rights reserved.
Curriculum/Programming Languages/Python (Professional)/Python Environment Setup
35 minBeginner

Python Environment Setup

After this lesson, you will be able to: Set up a professional Python environment with pyenv, virtual environments, pip, and the modern pyproject.toml.

Python's biggest beginner trap is environment management. Get this right once and the rest of the track flows.

This is a free introductory lesson. No purchase required.

Why environment management matters

Your laptop has one Python. Project A needs 3.10; Project B needs 3.12; the OS uses Python for itself. Mixing them = breaking things. Virtual environments isolate each project's dependencies. pyenv lets you install many Pythons side by side and pick per-project.

Modern Python setup

Install once; use forever.

bash
# pyenv (macOS / Linux)
brew install pyenv # or curl https://pyenv.run | bash
pyenv install 3.12.4
pyenv install 3.11.9
pyenv global 3.12.4
# Per-project: a .python-version file pins the version
cd my-project && pyenv local 3.12.4
# Virtual environment (built-in)
python -m venv .venv
source .venv/bin/activate # Linux/macOS
.venv\Scripts\activate # Windows
pip install requests
deactivate
# Modern alternative: uv (10x faster pip + venv replacement)
curl -LsSf https://astral.sh/uv/install.sh | sh
uv venv && uv pip install requests

requirements.txt vs pyproject.toml

requirements.txt: a flat list of `package==version` lines. Old default; works everywhere. pyproject.toml (PEP 621): the modern standard. One file declares dependencies, dev-deps, build config, tool config. Lockfiles: pip-tools, poetry, or uv generate exact-version lockfiles for reproducible installs. Default for new projects in 2026: pyproject.toml + uv (or poetry).

Common mistakes only experienced Python devs avoid

Installing packages globally with `sudo pip install`. Eventually breaks the system Python. Skipping virtual envs. Every project pollutes the same shared site-packages. Pinning to no version OR exact patch version on every dep. Pin majors, let patches float, lockfile for reproducibility. Forgetting `.venv` in .gitignore.

Quick Check

Why use a virtual environment?

Pick the cleanest answer.

Back to Python (Professional)
Python Fundamentals (Modern Python 3.12+)→