Lesson · Getting Started
Installing Python & Environment Setup
57 min readInstalling Python & Environment Setup
A correct development environment removes friction from every later lesson. You will install Python, understand how the interpreter is found, and create an isolated place for project dependencies.
Learning goals
- Install a supported Python 3 release and confirm which executable your terminal runs with
python --versionandwhere pythonorwhich python3. - Explain what a virtual environment isolates and why a project should not install its packages into the system Python.
- Create an environment with
python -m venv .venvand activate it so thatpythonresolves to the environment's own interpreter. - Say how the
pythonandpython3command names differ by platform, and when thepylauncher is the better tool on Windows. - Diagnose the common failure where a new interpreter is installed but
PATHstill resolves an older one.
Mental model
Verification comes before isolation on purpose: only after you can name the interpreter your shell resolves is it meaningful to point an environment at it. The final state to aim for is one interpreter and one package set shared by your terminal, your editor, and your tests.
Mental model
read it top to bottom
install a supported Python ↓ verify the executable: python --version, where python3 choose one interpreter for the project ↓ isolate it with a virtual environment (python -m venv .venv) activate the environment, then run scripts and tools through it
Core idea
One interpreter, chosen explicitly, should serve your terminal, your editor, and your project's installed packages. The two checks that keep this honest are the reported version and the resolved executable path, and a virtual environment adds the third piece, the package set, as one folder you can delete and recreate.
Installing Python
Install a supported Python release from a trusted distribution and know which executable your terminal will run. Keep system Python concerns separate from project-specific virtual environments.
Verifying installation
Verify both the reported Python version and the executable path. This catches the common case where a new interpreter is installed but the shell still resolves an older one.
python vs python3
On Windows, the python command usually resolves to an installed interpreter, and the py launcher can select among versions; on macOS and Linux, python3 is the reliable name because python may be missing or may point at an older release. Inside a virtual environment both platforms expose a python command that refers to the environment's own interpreter.
Running the interpreter
The interactive interpreter reads one input at a time, evaluates it, and displays results. It is ideal for experiments but does not replace a reproducible script or test.
Running .py files
A .py file is executed by the selected Python interpreter. Top-level statements run in order, and when the file is the entry script its module name is normally __main__.
Python launcher
On Windows, the Python launcher can select among installed Python versions without depending entirely on PATH. Version-selection behavior is platform specific.
PATH basics
PATH is an operating-system search list used to resolve command names to executables. Misconfigured PATH is a common reason python runs a different interpreter than expected.
IDE / editor setup
An editor should make the active interpreter visible and provide syntax, linting, debugging, and terminal access without hiding how Python itself runs. Keep environment selection explicit.
Terminal basics
The terminal runs the shell, and every command runs in a current working directory that relative paths resolve against; cd changes it, and each new session starts back at your home directory. Command names are found through PATH, so where python on Windows and which python3 on macOS and Linux show exactly which executable a name will launch.
Interactive shell
The interactive interpreter reads one input at a time, evaluates it, and displays results. It is ideal for experiments but does not replace a reproducible script or test.
Virtual environments preview
A virtual environment isolates installed packages and interpreter-facing configuration for one project. It reduces dependency conflicts and makes project setup reproducible.
Walkthrough
python --versionasks the interpreter thatPATHresolves to identify itself; if it prints an older release than the one you installed, the search order is the problem, not the installation.python -m venv .venvruns the standard library'svenvmodule with that same interpreter and creates a project folder.venvwhich holds its ownpythonandpip.- The last two lines call the environment's interpreter by path instead of by name:
.venv/bin/pythonon macOS and Linux,.venv\Scripts\pythonon Windows. Calling by path proves the environment works before you activate it, and after activation plainpythonshould resolve to the same file. - Predict before running: which interpreter each of the four commands will use on your machine, and what
.venv/bin/python -m pip --versionwould print if the environment folder were deleted.
Experiments to try
- Print the resolved executable from inside and outside an activated environment:
python -c "import sys; print(sys.executable)". The two paths should differ only by the.venvpart. - Run
.venv/bin/python -m pip list(or theScriptsform on Windows) and count how few packages a fresh environment contains compared with your global Python. - On Windows, run
py -0to list the installed interpreters and compare it withpython --version; elsewhere run bothpython3 --versionandpython --versionand note which command exists. - Delete
.venv, recreate it withpython -m venv .venv, and checksys.executableagain. Record what stays the same and what disappears.
Common mistakes
- Installing Python but never verifying the path: the shell keeps resolving an older interpreter, so
pip installandpython script.pytouch different environments. - Installing packages into the system Python before any virtual environment exists: those packages follow every project on the machine and can break tools the operating system relies on.
- Activating the environment once and assuming later terminals inherit it: every new terminal session starts from the global
PATHuntil you activate again or point the editor at the interpreter explicitly. - Using the wrong activation path for the platform:
.venv\Scripts\activateon Windows,.venv/bin/activateon macOS and Linux; a missingactivateusually means the wrong path shape for the operating system.
Practice: Easy
- Run
python --version, thenpython -c "import sys; print(sys.executable)", and write down both answers. State which one proves which executable will run your code. - Create
.venvwith the worked example and run.venv/bin/python -m pip --version(or theScriptspath on Windows). Note whether the printed path contains.venv. - Run
python -m venv --helpand list three options it accepts. Explain in one sentence what the module does when given only a folder name.
Practice: Medium
- Break
PATHfor one terminal session by launching a shell without the directory that holdspython, then runpython --versionthere. Record the exact error or the different interpreter that answers. - Create two environments,
.venv-aand.venv-b, and install a different package in each with that environment's ownpip. Prove withpip listthat the two package sets do not leak into one another. - Point your editor at
.venv's interpreter, then open a new integrated terminal and comparesys.executablethere with the editor's run action. Explain any mismatch.
Practice: Hard
- Write a
setupnote or script a teammate on another operating system can follow to reach the same state: install, verify, create the environment, install one dependency, run a test command. Name the step that is platform specific. - Reproduce the "new interpreter is shadowed" failure with two Python installations, change which one
PATHfinds first, and capturepython --versionandpip --versionbefore and after. - Compare
python -m venv .venvwith the third-partyvirtualenvtool by reading each help output: list one capability each has and one situation where the standard library module is the better default.
Lesson checklist
- I can install a supported Python and prove which executable my terminal runs.
- I can create and activate a virtual environment and show that
pythoninside it resolves to.venv. - I can explain what
PATHdecides and whypythonandpython3are not interchangeable on every platform. - I can name the platform difference between the
.venv/binand.venv\Scriptslayouts.
Remember
A project is reproducible when its interpreter and its packages are chosen on purpose. Install Python, verify the executable, and give each project a virtual environment that activation makes the default; those habits remove the mismatched-environment failures that make code behave differently on different machines.
Interview angles
What is the main purpose of **Installing Python**?+
Install a supported Python 3 release from a trusted source, and know which executable your terminal resolves when you type python. Keeping the system interpreter separate from project environments prevents one project's packages from affecting every other project.
What should you pay attention to when using **Verifying installation**?+
Verify both the reported Python version and the executable path. This catches the common case where a new interpreter is installed but the shell still resolves an older one.
How does **python vs python3** fit into this lesson?+
On Windows the python command usually resolves to an installed interpreter, and py can select among versions; on macOS and Linux python3 is the reliable name because python may be missing. Inside a virtual environment both platforms expose a python command that refers to the environment's own interpreter.
Why can `pip install` land in a different environment than the `python` you run?+
pip and python are resolved independently through PATH; if activation was skipped or another interpreter comes first, the pair can point at different installations, so packages installed by one are invisible to the other. Checking sys.executable and the path in pip --version shows which pair you are using.