Virtual Environments and Package Management
Manage Python packages properly with venv and pip — avoid the "works on my machine" problem
A virtual environment is an isolated Python installation for a specific project. It keeps project dependencies separate — so "Project A" can use pandas 1.5 and "Project B" can use pandas 2.0 without conflict.
This matters for data analyst roles because companies often have strict package versions and you will need to replicate environments on new machines or share code with colleagues.
Example
Key Points
- ✓Never install packages in the global Python installation for project work — always use venv
- ✓pip freeze > requirements.txt saves the exact versions of all installed packages
- ✓pip install -r requirements.txt installs everything from requirements.txt
- ✓Anaconda is popular in data science — it includes Python, Jupyter, and 250+ data packages pre-installed
- ✓In VS Code: select interpreter (Ctrl+Shift+P → Python: Select Interpreter) to use your venv
Practice Question
You want to share your Python data project with a colleague so they can run it with identical package versions. What file should you include?