---
title: "How do virtual environments work and why should I use them?"  
description: "How do virtual environments work and why should I use them?"  
author: "Gabriela Gómez"  
published: 2026-11-15  
updated: 2026-11-15  
canonical: https://www.mindstick.com/forum/163033/how-do-virtual-environments-work-and-why-should-i-use-them  
category: "python"  
tags: ["python", "virtual environment", "venv", "pip", "Dependency Management"]  
reading_time: 1 minute  

---

# How do virtual environments work and why should I use them?

I installed packages globally and now two projects need different versions of the same library. How do I stop this?

## Replies

### Reply by Laura De Rosa

A virtual environment is a separate folder containing its own copy of the Python interpreter links and its own installed packages. Each project gets its own, so versions never clash and your system Python stays clean.

On Windows:

```
python -m venv .venv
.venv\Scripts\activate
pip install requests
pip freeze > requirements.txt
```

On macOS and Linux, activate with `source .venv/bin/activate`.

Later, anyone can recreate the same setup with `pip install -r requirements.txt`.

Tips:

- Do not commit the .venv folder. Add it to .gitignore.
- Commit requirements.txt (or pyproject.toml) instead.
- Tools such as pipx, Poetry, uv and conda manage environments too, but venv comes with Python and is enough to start.


---

Original Source: https://www.mindstick.com/forum/163033/how-do-virtual-environments-work-and-why-should-i-use-them

Copyright © MindStick Software Pvt. Ltd. This Markdown version is provided for developers, AI systems, and offline reading.
