Installing Python, pip & Virtual Environments
BeginnerEvery real Python project isolates its dependencies in a virtual environment (venv) and installs packages with pip — the #1 habit that separates beginners from professionals.
Overview
Installing Python is easy; managing it is where beginners get burned. Two rules professionals follow from day one: (1) never install project packages globally — every project gets its own virtual environment, so Project A needing requests 2.31 and Project B needing 2.28 never fight; (2) pin your dependencies in a requirements.txt so any laptop (or server) can recreate the exact setup. This is Python's equivalent of Maven/Gradle dependency management in Java — simpler, but only if you build the venv habit early.
venv + pip — the Professional Workflow
python -m venv creates an isolated environment (a folder with its own interpreter and site-packages). Activating it makes pip install into that folder only. Freeze the exact versions to requirements.txt and commit that file — never commit the venv folder itself.
# Create and activate a virtual environment
python -m venv .venv
# Windows:
.venv\Scripts\activate
# macOS/Linux:
source .venv/bin/activate
# Install packages INSIDE the venv
pip install fastapi uvicorn requests
# Save exact versions for teammates/servers
pip freeze > requirements.txt
# On another machine — recreate everything
pip install -r requirements.txt
# Leave the environment
deactivateChecking Your Setup
python --version confirms the interpreter; which python (or where python on Windows) confirms WHICH interpreter is active — the most common beginner bug is installing a package into one Python and running another.
python --version # Python 3.12.x
pip --version # note the path — should point inside .venv
# Inside Python — quick sanity check
>>> import sys
>>> sys.executable # full path of the running interpreter
'.../.venv/Scripts/python.exe'
>>> sys.version_info
sys.version_info(major=3, minor=12, ...)Key Points to Remember
- 1One project = one venv. Always. Activate before installing anything
- 2requirements.txt (pip freeze) makes environments reproducible — commit it, never commit .venv
- 3pip installs from PyPI; pip install -U upgrades; pip uninstall removes
- 4"ModuleNotFoundError but I installed it" almost always means wrong interpreter/venv active
Interview Questions
Sign in to ask AriaWhat problem do virtual environments solve? What happens without them?
What is the difference between pip freeze and pip list, and why does requirements.txt matter for deployment?
Ask Aria about Installing Python, pip & Virtual Environments
Your personal AI tutor — ask anything about this concept
Revision Status
Personal Notes
Sign in to save personal notes for this topic.
Discussion
Sign in to join the discussion.