Python Basics — Installation & Setup
Installation & Setup
Before you can write Python code, you need Python installed on your computer. This guide covers installation on all major platforms.
Check If Python Is Already Installed
Open your terminal (or Command Prompt on Windows) and type:
python --version
Or on some systems:
python3 --version
Expected output:
Python 3.12.1
If you see Python 3.10 or higher, you’re good to go! Skip to the REPL Walkthrough section.
Installing Python on Windows
Option 1: Python.org (Recommended)
- Go to python.org/downloads
- Click “Download Python 3.x.x” (the big yellow button)
- Run the installer
- Important: Check the box ✅ “Add Python to PATH” — this is critical
- Click “Install Now”
Option 2: Microsoft Store
- Open the Microsoft Store
- Search for “Python”
- Install the latest Python 3.x version
Verify Installation
Open Command Prompt (cmd) or PowerShell:
python --version
Python 3.12.1
pip --version
pip 23.3.1 from C:\Users\you\...\pip (python 3.12)
Installing Python on macOS
Option 1: Homebrew (Recommended)
If you have Homebrew installed:
brew install python
Option 2: Python.org
- Go to python.org/downloads/macos
- Download the macOS installer
- Run the
.pkgfile and follow the prompts
Verify Installation
python3 --version
Python 3.12.1
Note: On macOS, you typically use python3 and pip3 (not python and pip) because macOS may have an older Python 2 pre-installed.
Installing Python on Linux
Ubuntu / Debian
sudo apt update
sudo apt install python3 python3-pip python3-venv
Fedora / RHEL / CentOS
sudo dnf install python3 python3-pip
Using pyenv (Advanced — Any Linux Distro)
pyenv lets you install and manage multiple Python versions:
curl https://pyenv.run | bash
pyenv install 3.12.1
pyenv global 3.12.1
Verify Installation
python3 --version
Python 3.12.1
pip3 --version
pip 23.3.1 from /usr/lib/python3/dist-packages/pip (python 3.12)
The Python REPL
REPL stands for Read-Eval-Print Loop. It’s an interactive Python shell where you type code and see results immediately.
Starting the REPL
python3
Output:
Python 3.12.1 (main, Dec 7 2024, 00:00:00)
[GCC 13.2.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>>
The >>> prompt means Python is waiting for your input.
Try It Out
>>> 2 + 3
5
>>> "Hello" + " " + "World"
'Hello World'
>>> len("Python")
6
>>> type(42)
<class 'int'>
Exiting the REPL
>>> exit()
Or press Ctrl + D (macOS/Linux) or Ctrl + Z then Enter (Windows).
Verifying pip
pip is Python’s package manager — you’ll use it to install third-party libraries. It comes bundled with Python 3.4+.
pip3 --version
pip 23.3.1 from /usr/lib/python3/dist-packages/pip (python 3.12)
Quick pip Test
pip3 install requests
Successfully installed requests-2.31.0
If this works, pip is set up correctly. We’ll learn more about pip in the Modules & Packages chapter.
Troubleshooting Common Issues
| Problem | Solution |
|---|---|
python: command not found |
Use python3 instead, or add Python to your PATH |
pip: command not found |
Use pip3 instead, or run python3 -m pip |
| Wrong Python version | Use pyenv to manage multiple versions |
| Permission denied | Use pip3 install --user package or use a virtual environment |
| SSL certificate errors | Update your system certificates or reinstall Python |
Summary
- Download Python 3.10+ from python.org
- Windows users: Always check ✅ “Add Python to PATH”
- macOS users: Use
python3andpip3 - The Python REPL lets you test code interactively
pipis the package manager — verify it works withpip3 --version
Next up: Your First Program →