- Verify whether Python is already installed and determine its version
- Install Python on macOS, Linux, and Windows using the recommended approach for each platform
- Use the Python REPL to execute expressions interactively
- Create and run a Python script from the command line
- Install third-party packages using pip and understand its role in the ecosystem
You cannot learn to swim by reading about water. At some point, you need to get in the pool. This chapter is about getting in the pool — installing Python on your machine, confirming that it works, writing your first program, and running it. The setup process is mercifully simple, but there are a few pitfalls that trip up beginners, and understanding what is actually happening when you type python3 will save you hours of confusion later.
Checking What You Already Have
Before installing anything, find out what is already on your machine. Open a terminal — Terminal on macOS, any terminal emulator on Linux, Command Prompt or PowerShell on Windows — and type:
python3 --version
If Python is installed, you will see something like Python 3.12.4. The exact number matters less than the fact that it starts with 3. If you get command not found, Python either is not installed or is not on your system's PATH — the list of directories the operating system searches when you type a command.
On some systems, particularly older Linux installations, python (without the 3) points to Python 2. Do not use it. Always type python3 explicitly until you are certain what python points to on your machine.
python3 --version # This is what you want
python --version # Might be Python 2 — check before trusting it
Installing on macOS
macOS does not ship with a usable Python 3 out of the box in recent versions. Apple removed the system Python 2 in macOS 12.3 and has not replaced it with Python 3. You have two good options.
The simplest is to install Apple's Command Line Tools, which include a copy of Python 3. Run xcode-select --install in the terminal and follow the prompts. Once it finishes, python3 should work.
The better option for serious development is Homebrew, the unofficial package manager for macOS. If you do not already have Homebrew, install it from brew.sh, then run:
brew install python
Homebrew installs Python 3 and links python3 and pip3 into your PATH automatically. It also makes upgrading painless: brew upgrade python and you are done.
Installing on Linux
Most Linux distributions include Python 3 in their default installation. On Debian and Ubuntu:
sudo apt update
sudo apt install python3 python3-pip python3-venv
On Fedora:
sudo dnf install python3 python3-pip
On Arch:
sudo pacman -S python python-pip
Linux is where Python feels most at home. The package managers handle dependencies, updates, and multiple versions with minimal fuss. If you need a specific Python version that your distribution does not ship, pyenv is the tool to reach for — it compiles and manages multiple Python versions side by side. But for now, the system Python 3 is perfectly fine.
Installing on Windows
Windows has historically been the most awkward platform for Python development, but it has improved enormously. The recommended approach is to download the installer from python.org. Click the big yellow button, run the installer, and — this is critical — tick the box that says "Add python.exe to PATH" before clicking Install. If you miss this, python will not work from the command line, and you will spend twenty minutes searching for why.
Alternatively, you can install Python from the Microsoft Store, which handles the PATH configuration for you. Either method works. Once installed, open Command Prompt or PowerShell and verify:
python --version
Note that on Windows, the command is python rather than python3, because Windows does not have a legacy Python 2 to conflict with.
The REPL
Once Python is installed, type python3 (or python on Windows) with no arguments. You will be greeted by something like this:
Python 3.12.4 (main, Jun 6 2024, 18:26:44)
[Clang 15.0.0 (clang-1500.3.9.4)] on darwin
Type "help", "copyright", "credits" or "license" for more information.
>>>
Those three chevrons (>>>) are the REPL prompt — short for Read-Eval-Print Loop. The REPL reads an expression, evaluates it, prints the result, and loops back for more. It is the single most valuable learning tool Python offers.
>>> 2 + 3
5
>>> "hello" + " " + "world"
'hello world'
>>> len("Python")
6
Notice that the REPL prints the result of each expression automatically. You do not need print() here — the loop does the printing for you. This makes it ideal for experimenting: try an idea, see the result, adjust, repeat.
To exit the REPL, type exit() or press Ctrl+D on macOS and Linux, Ctrl+Z followed by Enter on Windows.
Your First Script
The REPL is perfect for experimentation, but real programs live in files. Create a file called hello.py using any text editor — even Notepad will do — and type the following:
# hello.py — my first Python script
print("Hello, world!")
name = input("What is your name? ")
print(f"Pleased to meet you, {name}.")
Save the file, open a terminal in the same directory, and run it:
python3 hello.py
You should see Hello, world! followed by a prompt for your name. Type it, press Enter, and the program responds. You have just written, saved, and executed a Python program. Everything from here is refinement.
The # character starts a comment — text that Python ignores entirely. Comments are for human readers: future you, your colleagues, anyone who needs to understand what the code does and why. Write them generously.
Choosing an Editor
You can write Python in anything that produces plain text files. A word processor will not do — the invisible formatting characters it inserts will confuse the interpreter — but any proper text editor works.
VS Code (Visual Studio Code) is the most popular choice in 2026. It is free, cross-platform, and its Python extension provides syntax highlighting, autocompletion, integrated debugging, and linting out of the box. If you are unsure what to use, start here.
PyCharm by JetBrains is a full-featured Python IDE with deeper refactoring tools and a built-in debugger. The Community Edition is free and more than sufficient for learning. Professional Edition adds web framework support and database tools.
Vim and Emacs are terminal-based editors beloved by experienced developers. They have steep learning curves but reward the investment with unmatched speed. If you are already a Linux user, you may already have a preference.
For absolute beginners who find VS Code overwhelming, Mu is a simple editor designed specifically for learning Python. It has a large Run button and a built-in REPL. It does one thing and does it well.
The editor matters less than you think. Pick one, learn it, and change later if you outgrow it.
Installing Packages with pip
Python's standard library is extensive — the "batteries included" philosophy means that common tasks like reading JSON, making HTTP requests, and working with dates are covered out of the box. But sooner or later, you will need a third-party package.
pip is Python's package installer. It downloads packages from the Python Package Index (PyPI) and installs them on your system. To install a package:
pip3 install requests
This downloads and installs requests, the most popular library for making HTTP requests. You can then use it in your code:
import requests
response = requests.get("https://api.github.com")
print(response.status_code) # Output: 200
To see what you have installed:
pip3 list
To uninstall a package:
pip3 uninstall requests
A word of caution: installing packages globally with pip can create conflicts between projects that need different versions of the same library. The solution is virtual environments, which we will cover in detail in Chapter 15. For now, just know that pip exists and how to use it.
Reading the Documentation
Python has some of the best official documentation of any programming language. It lives at docs.python.org and covers every built-in function, every standard library module, and the language reference itself.
The most useful section for a beginner is the Library Reference, which documents every module in the standard library with examples. When you want to know what os.path.join() does, or how datetime.strptime() parses a date string, this is where you go.
The built-in help() function in the REPL is the same documentation, accessible offline:
>>> help(len)
Help on built-in function len in module builtins:
len(obj, /)
Return the number of items in a container.
Reading documentation is a skill that improves with practice. The official docs can feel dense at first, but they are precise and reliable — which is more than can be said for most things you find on the internet.
Your environment is set up. You have a working Python installation, a way to run code interactively and from files, a package installer, and documentation within arm's reach. Everything that follows builds on this foundation.