Virtual Environments and Package Management
Set up isolated Python environments and manage packages with pip and conda
Virtual environments solve the "it works on my machine" problem. They let each project have its own Python packages and versions — preventing conflicts between projects. This is professional best practice that every data analyst should know.
Example
Key Points
- ✓Always create a virtual environment for each project — never install globally
- ✓pip freeze > requirements.txt captures all installed packages and their exact versions
- ✓conda is an alternative to pip/venv — preferred when working with Anaconda distribution
- ✓If on Anaconda: conda create -n myenv python=3.11 and conda activate myenv
- ✓Include requirements.txt in every GitHub project so others can reproduce your environment
Practice Question
Which command saves all currently installed packages to a requirements.txt file?