Python Environment Setup
In this page:
Installing the Interpreter
The official CPython interpreter is available as a free installer from python.org for Windows, macOS, and Linux. On Windows specifically, ticking "Add python.exe to PATH" during installation is the step most beginners miss, and skipping it means the python command won't be recognized in your terminal afterward.
Example: Installing the Interpreter
# Download the installer from python.org
# On Windows, check "Add python.exe to PATH" during setup
print("Python interpreter installed and ready")
Text Editors and IDEs
Popular choices range from lightweight code editors like VS Code with the Python extension, to Python's own bundled IDLE editor, to full-featured IDEs like PyCharm that add debugging and refactoring tools. Which one you pick matters less than picking one and getting comfortable with its shortcuts.
Example: Text Editors and IDEs
# Popular editors: VS Code (with Python extension), IDLE, PyCharm
print("Pick an editor and get comfortable with it")
Writing Your Code
Python source files use the .py extension so both your editor and the interpreter recognize them as executable Python code. Any plain text editor works for writing the file itself — the extension, not the editor, is what makes it a Python program.
Example: Writing Your Code
# Save this file as hello.py
print("The .py extension marks this as Python source code")
Running Your Code
Running python filename.py (or python3 on many Linux/macOS systems) from your terminal, inside the folder containing the file, hands the script to the interpreter for execution line by line. If the command isn't found, that usually points back to the PATH step from installation.
Example: Running Your Code
# Run from your terminal:
# python filename.py
print("Executed line by line by the interpreter")
Verifying the Setup
Before writing anything complex, running a one-line print("hello") script confirms the interpreter is installed correctly and your terminal is pointed at the right file. Catching setup problems on something trivial saves confusion later when a real bug and a broken environment start looking the same.
Example: Verifying the Setup
print("hello")
Chapter Quiz — Complete all 14 topics to unlock
0/14 topics done
Complete these topics first: