Python VS2026
🐍 Python 2026 › Lesson 29: Virtual Environments and Project Management
Lesson 29 of 30

Virtual Environments and Project Management

venv, pip freeze, requirements.txt, and managing dependencies professionally.

Why Virtual Environments?

Different projects often need different package versions. A virtual environment creates an isolated Python installation per project, preventing conflicts.

Creating a Virtual Environment

In Visual Studio 2026, right-click Python Environments in Solution Explorer → Add Environment. Or from the terminal:

# Create
python -m venv .venv

# Activate (Windows)
.venv\Scripts\activate

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

# Deactivate
deactivate

Managing Dependencies

pip install requests pandas           # install
pip install requests==2.31.0          # specific version
pip freeze > requirements.txt         # snapshot
pip install -r requirements.txt       # restore on another machine
pip list                               # what's installed
pip show pandas                        # details about a package
pip uninstall requests                 # remove

Project Structure Best Practices

my_project/
├── .venv/               # virtual environment (not in git)
├── src/
│   ├── __init__.py
│   └── main.py
├── tests/
│   └── test_main.py
├── requirements.txt
└── README.md
✅ .gitignore
Always add .venv/ and __pycache__/ to your .gitignore so they are never committed to version control.