- One global Python install mixes package versions across projects. Both can break.
- Create a venv per project with
python -m venv .venv, then activate it before any pip install. - Share the setup:
pip freeze > requirements.txt. A teammate runspip install -r requirements.txt. - Never commit the venv folder. Never install project libraries into the system Python.
- uv and pipx are handy extras. Interviews still expect venv and requirements.txt.
Monday, 10.15 am, a shared desk in Chennai. Your teammate cloned the repo, typed pip install, and the invoice script that ran on Friday night now dies with ImportError. Same laptop. Same Python. Over the weekend a side project quietly upgraded requests.
This is not bad luck. This is one global package folder feeding five different projects.
What is a Python virtual environment, in one line?
A virtual environment is a private folder of Python packages that belongs to one project. Search python venv and that is the answer: stop pouring every library into the one Python the whole machine uses.
Think of a tiffin box. Project A keeps its web framework in one box. Project B keeps another version in a second box. They never mix. pip is the spoon you pick up only after you open the right box. requirements.txt is the chit you send a teammate so they pack the same lunch.
It costs nothing. venv ships with Python. If Python 3 is on the laptop, you already have this.
What goes wrong if you skip venv?
Skip venv and every pip install lands in global site-packages. Project A needs one version of requests. Project B needs a plugin that only works with a newer one. You install for B at lunch. A crashes at 4 pm. Nobody changed A's code.
On Linux that global install can fight the Python the OS itself uses. You get permission errors. A few people sudo pip install and bruise system tools. Windows users meet it later: two projects, one pip, a trail of module-not-found after a reinstall.
Then the teammate. You say it works on your machine. They install from memory. pandas comes out different. Report numbers shift. The standup becomes a version argument. A venv plus a freeze file ends that argument.
Run this after you think you activated the env. If the path is still the system Python, you are not inside the box.
import sys
from importlib.metadata import PackageNotFoundError, version
print("Python:", sys.executable)
for name in ("requests", "pandas"):
try:
print(f"{name}: {version(name)}")
except PackageNotFoundError:
print(f"{name}: not installed")
How do you create, activate and deactivate it on each OS?
One project folder. One .venv inside it. Do not build a single env in your home directory for all Python work. That is just a second global install with extra steps.
On Windows, open cmd or PowerShell in the project folder. The py launcher is the reliable one:
py -m venv .venv
In cmd, activate with .venv\Scripts\activate. In PowerShell, use .venv\Scripts\Activate.ps1. If PowerShell blocks the script, run Set-ExecutionPolicy -Scope CurrentUser RemoteSigned once, then activate again. Your prompt should show (.venv).
On macOS or Linux, use python3. Some Ubuntu machines need the venv package from apt first if the module is missing.
python3 -m venv .venv
Then source .venv/bin/activate. Same (.venv) prefix on the prompt.
To leave the env, type deactivate on every OS. The prefix disappears. You did not delete the folder. You just stepped out. Delete .venv only when you want to rebuild it from requirements.txt.
After activate, upgrade pip inside the env, then install what the project needs. Do not use sudo. Run python -m pip install --upgrade pip.
You can create the env from Python too. Creating the folder is not the same as using it. Still activate after this runs.
from pathlib import Path
import venv
env_dir = Path(".venv")
venv.create(env_dir, with_pip=True)
print("Created", env_dir.resolve())
How do pip freeze and requirements.txt help a teammate?
Activate the env. Install only what this project needs. Then freeze. The file is a shopping list with versions pinned, so Monday's machine matches Friday's.
python -m pip install requests
python -m pip freeze > requirements.txt
Hand the teammate the code plus requirements.txt. Not the .venv folder. They create their own env, activate, then run python -m pip install -r requirements.txt.
Freeze from the activated env, not from global Python, or you will pin eighty unrelated packages from old experiments.
A tiny script that needs requests looks like this. Run it only after the install inside the venv.
import requests
url = "https://httpbin.org/get"
response = requests.get(url, timeout=10)
response.raise_for_status()
data = response.json()
print("status:", response.status_code)
print("url:", data.get("url"))
Put that file in git. Put requirements.txt in git. Keep .venv in .gitignore. A teammate in Pune should rebuild, not copy a Windows env onto Linux.
Where do uv and pipx fit in?
uv is a fast installer and venv helper that a lot of teams now keep beside pip. pipx installs command-line tools such as Ruff or Poetry into their own isolated envs, so those tools do not sit inside your project venv or the system Python. Learn them when you have venv muscle memory. For interviews and for the first office repo, python -m venv, pip, and requirements.txt are still the baseline.
Which mistakes get people into trouble?
Committing .venv is the classic. The folder is huge, it is tied to one OS, and git will hate the binary noise. Add .venv/ to .gitignore on day one. Commit requirements.txt instead.
Global installs are the other trap. pip install requests with no activate writes to the system. The next project inherits it. Need a CLI tool for every project? Use pipx. Need a library for this repo? Activate first.
Other landmines: forgetting to activate, then installing into what you think is the project but is actually global. Moving the folder after create, because some envs bake in absolute paths. Using sudo. Zipping a teammate's venv from Windows onto a Mac.
Where does this show up in Indian companies and interviews?
Service-company training batches still walk freshers through venv on day two of Python. Product teams at places like Zoho, Freshworks, Razorpay, and the Chennai GCC desks expect a clean repo: .gitignore, requirements.txt, no uploaded env. Interviewers ask why two apps on one laptop need isolation, or they watch you pip install during a live task. Saying you install globally is a red flag. Saying venv, freeze, teammate installs from the file is the expected junior answer. Docker shows up later. This is the floor.
What should you do now?
Do not only read this on the bus. Do a 20-minute drill.
Create a folder called invoice-demo. Make a .venv inside it. Activate. Upgrade pip. Install requests. Save the httpbin script above as fetch_demo.py. Run it. Freeze to requirements.txt. Add a .gitignore that lists .venv/. Copy only fetch_demo.py and requirements.txt into a second folder. Create a fresh venv there, install from the file, run the script again. If both runs print status 200, you know how to share a project.
Tomorrow, open the repo you actually work on. If there is no venv, make one. If there is no requirements.txt, freeze from a clean env. Send that file, not a screenshot of pip list.




Comments (0)
Be the first to comment!