Skip to main content
Brave Programmer Logo

BraveProgrammer

BraveProgrammer

HomeProjectsBlogsCoursesLessonsAbout

Site footer

BraveProgrammer

Free coding courses, practical tutorials, and real projects from BraveProgrammer. Learn web development with React, Next.js, and TypeScript.

Navigation

  • Home
  • Projects
  • Blogs
  • Courses

Resources

  • About
  • Lessons
  • Teach on BraveProgrammer

© 2026 BraveProgrammer. All rights reserved.

Virtual Environments and pip | Python Fundamentals lesson | BraveProgrammer
  1. Courses
  2. /
  3. Python Fundamentals

Lesson 35 of 55

·Python

Virtual Environments and pip

20 minutes

Course progress64%

What you'll learn

Keep these ideas in mind as you work through the lesson.

4 points
  • Virtual environments keep dependencies project‑specific.
  • `pip install` fetches packages from PyPI.
  • `pip freeze` records the exact package versions.
  • Deactivate with `deactivate`, or close the terminal.

Virtual Environments and pip

A virtual environment isolates a project's Python interpreter and its third‑party packages, preventing version conflicts across projects.

# Create a virtual environment named .venv
python -m venv .venv

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

# Activate (Windows)
.\\venv\\Scripts\\activate

# Upgrade pip inside the env
pip install --upgrade pip

# Install a library, e.g., requests
pip install requests

# Freeze exact versions for reproducibility
pip freeze > requirements.txt

Whenever you start work on the project, activate the environment first. Deactivate with the deactivate command or simply close the terminal.

Make it stickPractice what you've learned1 quiz · 5 practical tests · Optional activities from Python FundamentalsBrowse activities
Previous lessonLoggingContinue to lesson 36Packaging and DistributionBack to Python Fundamentals curriculum