Python Learning Series · @onlysamarrr · Day 29 / 30

Day 29: pip and Virtual Environments

Day 29 is about pip and virtual environments, not Python code. pip installs packages, and a venv gives each project its own isolated environment so package versions never clash between projects.

Phase: Intermediate · Reels: 141/450 – 145/450

Quick Answer

Day 29 is about pip and virtual environments, not Python code. pip installs packages, and a venv gives each project its own isolated environment so package versions never clash between projects.

What You Will Learn

Code

python -m venv .venv
source .venv/bin/activate
# Windows: .venv\Scripts\activate
pip install requests
pip freeze > requirements.txt
pip install -r requirements.txt
deactivate

Output

Day 29 is about terminal commands, so there is no Python output. Run the commands in your computer's terminal, in order.

Code Explained, Line by Line

  1. python -m venv .venv creates a separate environment called .venv inside the project.
  2. source .venv/bin/activate (Mac/Linux) or .venv\Scripts\activate (Windows) turns the environment on.
  3. pip install requests installs the package only inside this environment, not globally.
  4. pip freeze > requirements.txt saves the installed packages and versions to a file.
  5. pip install -r requirements.txt recreates the same setup on any new computer.
  6. deactivate turns the environment off.
Common Mistake: Installing every package globally makes project versions clash. Create a venv for every project.

Real-Life Use

Every professional Python project uses a venv plus requirements.txt so teammates get the same setup.

Practice Task: Create a venv for your project, install one package, and create requirements.txt.

Test Yourself — MCQs

Select (tick) an option, then tap Check answer to see instantly whether your answer is right or wrong, with an explanation. You can change your answer and check again.

Q1. What does python -m venv .venv create?

Q2. What does pip freeze > requirements.txt do?

Q3. What does pip install -r requirements.txt do?

Today's 5 Reels (from the 90-Day Plan Excel)

141/450Conceptpip kya hai
142/450Live demovenv banao demo
143/450Common mistakeGlobal install ki galti
144/450QuizQuiz: requirements.txt
145/450Interview / real lifeInterview: venv kyun
← Day 28Day 30 →