pip and Virtual Environments
You have a folder of bookshop sales and a plan to analyse it with pandas. Before any analysis, the tools have to be installed, and installed in a way that will not break the project you start next month. That is the job of pip and virtual environments.
The rule
One project, one environment; install inside it, record what you installed.
pip is Python's package installer. It downloads a library from the Python Package Index and puts it where Python can import it.
A virtual environment is a private folder holding its own Python and its own installed packages. Project A can keep pandas 2.1 while project B uses pandas 2.3, and neither notices the other.
python -m venv .venv # create the environment in a folder called .venv
source .venv/bin/activate # switch into it (Windows: .venv\Scripts\activate)
pip install pandas numpy matplotlib
pip freeze > requirements.txt # record exact versionsAnyone who gets your project later runs pip install -r requirements.txt inside their own fresh environment and gets the same versions.
Two other tools do the same job with a different style:
- conda manages environments and non-Python pieces (such as compiled maths libraries). Popular in scientific work.
- uv is a newer, very fast replacement for pip plus venv, driven by commands like
uv venvanduv pip install.
The idea is identical in all three: an isolated environment per project, plus a written list of what is in it.