Skip to Content
Course content

1: Installing Python on Windows, macOS, and Linux

Click on the "Edit" button in the top corner of the screen to edit your slide content.

A few years ago, I spent an entire afternoon helping a junior developer who was convinced that Python was "broken." He had followed a tutorial, installed the language, and yet every time he tried to use a modern feature like f-strings, his terminal screamed at him with a SyntaxError. The mystery? He was on a Mac, and when he typed python, the system was launching the ancient version 2.7 that Apple had bundled with the OS for a decade, rather than the version 3.11 he had just installed. He wasn't failing at coding; he was just talking to the wrong version of Python.

This is the "environmental hurdle." Before you write a single line of logic, you have to ensure your computer actually knows where the Python interpreter lives and which version should take priority. It sounds trivial, but path conflicts are the primary reason beginners quit in the first hour.

Handling the Windows Installation Trap

Windows is generally straightforward, but there is one single checkbox that will save you hours of frustration. When you run the installer from python.org, you'll see a small box at the bottom that says "Add Python to PATH." Check it. Seriously, do not skip this.

If you don't check that box, Windows won't know what the command python means when you type it into the Command Prompt or PowerShell. I've had to help countless devs manually edit their Environment Variables—a tedious process involving deep-diving into System Properties—just because they missed that one click. Once you've checked the box and finished the installation, you can verify it's working by opening a terminal and typing:

python --version

If it returns something like Python 3.12.x, you're golden.

Avoiding System Python on macOS

As I mentioned in that story about my junior dev, macOS can be tricky because it often comes with a pre-installed version of Python used by the operating system itself. You should almost never touch that system version; if you mess it up, you can actually break parts of macOS.

The professional way to handle this is via Homebrew. If you don't have Homebrew installed yet, it's the unofficial package manager for Mac and a lifesaver. Once Homebrew is set up, you just run brew install python. This installs a separate, clean version of Python 3 in a directory that doesn't interfere with the system files. One quirk to remember: on Mac, you might need to use the command python3 instead of just python to ensure you aren't accidentally calling that old system version.

Managing the Linux Pipeline

If you're on Linux, you're likely already in a Python-friendly environment. Most distributions (like Ubuntu or Fedora) come with Python pre-installed. However, the version in the default repositories is sometimes a few months behind the latest release.

I usually recommend using the built-in package manager. On Ubuntu or Debian, that's apt. You'll want to run sudo apt update and then sudo apt install python3. Like macOS, Linux almost always distinguishes between the versions. If you type python and get a "command not found" error, try python3. It's a common point of confusion, but it's just the OS's way of making sure it doesn't overwrite legacy scripts that might still rely on Python 2.




📋 Practical Task

Verifying the Python Interpreter Path

Now that you've installed Python, let's make sure your computer is pointing to the correct installation and not a hidden system version. We are going to write a tiny script that asks Python to tell us exactly where it is located on your hard drive.

Create a file named where_am_i.py and enter the following code:

import sys
print("The Python interpreter is located at:")
print(sys.executable)

Run this script from your terminal using python where_am_i.py (or python3 where_am_i.py).

Your Goal: Note the output path. If you are on Windows and the path includes AppData\Local\Microsoft\WindowsApps, you might be using the Windows Store shim. If you are on Mac and the path is /usr/bin/python, you are likely using the system version and should revisit the Homebrew installation steps to avoid future permission errors.

Rating
0 0

There are no comments for now.

to be the first to leave a comment.