Python foundations · Lesson 2 of 3
Install Python and manage project environments
Choose a Python installation and isolate each project’s dependencies.
Lesson
1. Concept and mental model
Use a currently supported Python release from python.org or your organization’s approved package source. Confirm the active interpreter with python --version or, on some systems, py --version. Multiple Python versions can exist on one machine, so verify which executable a terminal or editor actually runs. A virtual environment creates a project-local installation context; it prevents one project’s library upgrades from silently breaking another project.
2. How it works
Create an environment with python -m venv .venv, activate it for the current shell, then install packages using that environment’s python -m pip. Using python -m pip reduces ambiguity when several pip commands point to different interpreters. Record direct dependencies in a requirements file or project metadata and install from that record on another machine. Do not commit the environment folder itself; it contains machine-specific files and can be recreated.
3. Use it safely and effectively
Treat dependency upgrades as changes that need review and tests. Pinning every transitive dependency may be appropriate for reproducible deployments, while a library project may declare a compatible version range. Do not install packages with administrator privileges merely to resolve a project-local issue. If a command behaves unexpectedly, inspect python -m pip --version and the interpreter path before changing the global machine configuration.
4. Syntax reference
python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install requests5. Guided walkthrough
Create the environment from the project directory, activate it in the current terminal, and confirm that python and pip point inside .venv. Install only the libraries this project needs and record them so another developer can recreate the setup.
6. Common mistakes to avoid
- Installing a dependency globally because the wrong interpreter or pip executable was selected.
- Committing the generated .venv directory instead of the dependency manifest.
Visual guide
A repeatable Python setup
-
Step 01
Select
Choose and verify the Python interpreter.
-
Step 02
Isolate
Create and activate a virtual environment.
-
Step 03
Install
Install and record project dependencies.
Code examples
python -m venv .venv
.venv\Scripts\Activate.ps1
python -m pip install requests
A project environment is activated and requests is installed into it.
python --version
python -m pip --version
where.exe python
The interpreter and pip paths identify the active environment.
python -m pip freeze > requirements.txt
python -m pip install -r requirements.txt
Writes installed package versions and installs them from the manifest.
Key points
- Choose a Python installation and isolate each project’s dependencies.
- Prefer explicit, testable behavior over hidden side effects.
- Validate assumptions at system boundaries and handle failure deliberately.
Check your understanding
Practice
Your learning progress