What are pip and virtual environments in Python, and why do you use them?
pip is Python's package installer. It installs packages from PyPI and other indexes, and it manages the dependencies they declare, so asking for one package brings in the ones it needs. The commands you need are pip install, pip uninstall, pip list, pip show and pip freeze.
A virtual environment is an isolated directory containing its own copy of the Python interpreter and its own site-packages folder. When it is active, pip installs into that directory instead of the system one. You create one with python -m venv .venv, activate it with the activate script — source .venv/bin/activate on Linux and macOS, .venv\Scripts\activate in Windows — and from then on pip and python refer to the environment.
The reason this matters is dependency isolation. Two projects can need different versions of the same library, and without environments they would fight over the single system copy. Environments also make a project reproducible: the set of installed packages is described by a file, and everyone who installs from that file gets the same versions.
That file is usually requirements.txt, written with pip freeze and consumed with pip install -r requirements.txt. Modern projects increasingly use pyproject.toml instead, which declares the project itself along with its dependencies, and tools such as pip-tools, Poetry or uv manage the lock file that pins exact versions.
The practical rule for an interview is one virtual environment per project, always activate it before installing anything, and commit the dependency file so the next person can reproduce your setup.