Warming up the neural circuits...
By the end of this chapter you will:
A broken setup kills more beginners than syntax ever will. If you can't run a Python file, you can't learn Python. The good news: installing Python takes 5 minutes. The bad news: there are three common mistakes that waste hours.
This chapter walks you through the setup on Windows, macOS, and Linux. Follow the section for your OS, then verify the installation. If something breaks, check the "Common mistakes" section at the end.
Before we start, understand what you're installing and why:
When you install Python from python.org, you're installing CPython — the standard implementation of the Python language. It's written in C (hence the name) and is the most widely used Python interpreter.
The interpreter does three things:
Other interpreters exist (PyPy for speed, MicroPython for embedded devices, Jython for Java integration), but CPython is what you want for learning.
pip is Python's package installer. It downloads and installs libraries from PyPI (Python Package ), a repository of 500,000+ packages.
pip install requests # Install a package
pip install requests==2.28 # Install specific version
pip list # List installed packages
pip freeze > requirements.txt # Save dependenciespip is included with Python 3.4+. If you have Python 3, you have pip.
A virtual environment is an isolated Python installation for a specific project. Each project gets its own set of packages, so Project A can use requests==2.28 while Project B uses requests==2.31.
python -m venv venv # Create virtual environment
source venv/bin/activate # Activate (macOS/Linux)
venv\Scripts\activate # Activate (Windows)
pip install requests # Install in this environment only
deactivate # Deactivate when doneWe'll cover virtual environments in depth in Chapter 7. For now, just know they exist.
VS Code is a free, open-source code editor by Microsoft. The Python extension adds:
Other editors work (PyCharm, Sublime Text, Vim), but VS Code is the most popular for Python development.
Think of the Python toolchain like a kitchen:
Step 1: Download the installer
Go to python.org/downloads and click the big yellow "Download Python 3.12.x" . This downloads the installer for the latest stable version.
Step 2: Run the installer
Double-click the downloaded file. You'll see a screen with checkboxes at the bottom. This is the most important step:
✅ Check "Add Python.exe to PATH" (or "Add Python 3.12 to PATH")
If you skip this, you'll have to manually edit your system PATH later. Don't skip it.
Then click "Install Now" (not "Customize installation" — the defaults are fine).
Step 3: Verify the installation
Open a terminal:
Win + R, type cmd, press EnterIn the terminal, run:
python --versionYou should see something like Python 3.12.0. If you do, you're done.
The py launcher
Windows also installs the py launcher, which lets you run Python with py instead of python. This is useful if you have multiple Python versions installed:
py --version
py -3.12 script.py # Run with Python 3.12 specificallyFor this course, use python (not py) to stay consistent with macOS/Linux. But know that py exists.
macOS used to ship with Python 2.7 pre-installed, but that's gone in recent versions. You need to install Python 3 yourself.
Option A: python.org installer (recommended for beginners)
Go to python.org/downloads and download the macOS installer (a .pkg file). Double-click it and follow the prompts.
After installation, open Terminal and run:
python3 --versionNote: on macOS, the command is python3, not python. The python command might still point to Python 2 (if it exists at all).
Option B: Homebrew (for developers who use Homebrew)
If you already use Homebrew, you can install Python with:
brew install pythonThis installs Python 3 and makes it available as python3.
Verify the installation
python3 --versionYou should see Python 3.12.0 or similar.
Most Linux distributions ship with Python 3 pre-installed. Check with:
python3 --versionIf you see Python 3.8 or newer, you're good. If you need a newer version (3.12+), use your package manager:
Ubuntu/Debian:
sudo apt update
sudo apt install python3.12 python3.12-venvFedora:
sudo dnf install python3.12Arch:
sudo pacman -S pythonAfter installation, verify with python3 --version.
Once Python is installed, you can use the REPL (Read-Eval-Print Loop), an interactive shell where you can type Python code and see the results immediately.
Open a terminal and run:
python # Windows
python3 # macOS/LinuxYou'll see a prompt like >>>. This is the REPL. Type Python code and press Enter:
>>> 2 + 2
4
>>> print("Hello, world!")
Hello, world!
>>> exit()The REPL is your scratchpad for experimenting. You'll use it throughout this course.
To exit the REPL, type exit() or press Ctrl+D (macOS/Linux) or Ctrl+Z then Enter (Windows).
VS Code is the most popular editor for Python. It's free, fast, and has excellent Python support.
Step 1: Install VS Code
Download from code.visualstudio.com and install it.
Step 2: Install the Python extension
Ctrl+Shift+X)Step 3: Select the Python interpreter
File → New File → test.py)Ctrl+Shift+P (or Cmd+Shift+P on macOS) to open the Command PaletteVS Code will now use that interpreter to run your code and provide autocomplete.
Step 4: Configure settings
Open Settings (Ctrl+, or Cmd+,) and search for "Python". Set:
Step 5: Install a theme (optional)
A good theme makes code easier to read. Popular choices:
Install from the Extensions tab.
You'll use the terminal a lot in Python development. Here are the commands you need:
Navigate directories:
cd folder_name # Go into a folder
cd .. # Go up one level
pwd # Print current directory (macOS/Linux)
cd # Print current directory (Windows, use 'cd' alone)List files:
ls # List files (macOS/Linux)
dir # List files (Windows)Run Python:
python script.py # Run a Python file (Windows)
python3 script.py # Run a Python file (macOS/Linux)Create a folder:
mkdir folder_name # Create a folderOpen VS Code from terminal:
code . # Open current folder in VS Code| Mistake | Why it's wrong | Fix |
|---|---|---|
python command not found on Windows | Python isn't in your PATH | Re-run the installer and check "Add Python to PATH", or manually add C:\Users\<YourName>\AppData\Local\Programs\Python\Python312 to your PATH |
python opens Microsoft Store on Windows | Windows 10/11 has an alias that redirects python to the Store | Go to Settings → Apps → App execution aliases → Turn off "python.exe" and "python3.exe" aliases |
python works but python3 doesn't (or vice versa) | Different OS conventions: Windows uses python, macOS/Linux use python3 | Use the command for your OS. If you need both, create an alias or use py -3 on Windows |
| VS Code shows "Python not installed" even though it is | VS Code can't find the interpreter | Open Command Palette → "Python: Select Interpreter" → choose the correct path |
SyntaxError when running a Python 2 tutorial | Python 2 syntax (print "hello") doesn't work in Python 3 | Use Python 3 syntax: with parentheses |
Virtual environments: We'll cover these in Chapter 7, but know that professional Python projects use virtual environments to isolate dependencies. Don't install packages globally (pip install) for real projects — use python -m venv venv first.
Multiple Python versions: If you need multiple versions (e.g., 3.10 for one project, 3.12 for another), use pyenv (macOS/Linux) or the py launcher (Windows) to switch between them.
IDE alternatives: VS Code is the most popular, but PyCharm (by JetBrains) is also excellent. It's heavier but has more features out of the box. For this course, use VS Code.
python --version (Windows) or python3 --version (macOS/Linux). What version do you see?10 + 20, print("Hello, Python!"), exit(). What do you see?10 + 20, print("Hello, Python!"), exit()test.py with print("Hello from a file!") and run it from the terminal.print("Hello from a file!")python-test, open it in VS Code, create hello.py with print("Hello from VS Code!"), and run it with the Play button.print("Hello from VS Code!")Beginner:
"What's the difference between python and python3?"
pythonis the command on Windows;python3is the command on macOS/Linux. Both run Python 3. On Windows,python3might not exist (or might open the Microsoft Store). On macOS/Linux,pythonmight point to Python 2 (if it exists at all).
"What is the Python REPL?"
The REPL (Read-Eval-Print Loop) is an interactive shell where you can type Python code and see the results immediately. You start it by running
python(Windows) orpython3(macOS/Linux) in the terminal. It's useful for experimenting and testing small snippets.
Senior:
"Why is it important to add Python to your PATH during installation?"
The PATH is a list of directories your system searches when you type a command. If Python isn't in your PATH, the terminal can't find the executable, and you'll get "command not found". Adding Python to PATH lets you run from any directory.
python on Windows, python3 on macOS/Linux.python vs python3.I want to…
├── Install Python → python.org/downloads (Windows/macOS) or apt/brew (Linux)
├── Run Python → python (Windows) or python3 (macOS/Linux)
├── Open the REPL → python or python3 in terminal
├── Run a script → python script.py or python3 script.py
├── Select interpreter in VS Code → Ctrl+Shift+P → "Python: Select Interpreter"
└── Fix "command not found" → Add Python to PATH (Windows) or use python3 (macOS/Linux)What's the most important checkbox during Python installation on Windows?
pythonpython"What's the difference between the py launcher and the python command on Windows?"
The
pylauncher is a Windows-specific tool that lets you run Python withpyinstead ofpython. It's useful if you have multiple Python versions installed:py -3.10runs Python 3.10,py -3.12runs 3.12. Thepythoncommand runs the default version. On macOS/Linux, there's nopylauncher — usepython3instead.