2. Installing Python on macOS
1. Introduction
macOS includes a system version of Python, but it is often outdated and should not be used for development.
It is recommended to install the latest stable Python release separately.
2. Checking the Current Python Version
Open Terminal (press Cmd + Space, type Terminal, press Enter) and run:
python3 --version
If the version is older than 3.10 or missing, install the latest release.
You can also check if pip is available:
pip3 --version
3. Downloading the Official Installer
- Open a web browser.
- Visit the official download page: https://www.python.org/downloads/macos/
- The site will suggest the latest stable version (e.g., Python 3.12.x).
- Download the macOS 64-bit universal installer (.pkg file).
4. Installing with the .pkg Installer
- Locate the downloaded file in Downloads (example:
python-3.12.x-macosx10.9.pkg). - Double-click the
.pkgfile. - Follow the prompts:
- Continue → Agree to license → Select install location.
- Enter your administrator password when asked.
- After installation, Python is usually placed in
/usr/local/bin/python3.
5. Alternative: Installing with Homebrew
If you prefer the Homebrew package manager:
- Install Homebrew (if not already installed):
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Install Python:
brew install python
- Verify installation:
python3 --version
pip3 --version
6. Verifying Installation
Check that Python and pip are working:
python3 --version
pip3 --version
Expected output:
Python 3.12.2
pip 23.x.x
7. Troubleshooting
- Command not found: Restart Terminal or confirm the path with:
which python3
-
Multiple versions of Python:
- macOS may have an old system Python.
- Always use
python3instead ofpython.
-
pip missing: Install separately with:
sudo apt install python3-pip # if on Linux subsystem
brew reinstall python # if using Homebrew
- PATH issues: Add
/usr/local/binto your PATH if needed by editing~/.zshrcor~/.bashrc.
8. Uninstalling Python
- If installed via the
.pkgfile, manually remove from/Library/Frameworks/Python.framework/Versions/. - If installed with Homebrew, run:
brew uninstall python
9. Next Steps
✅ Python is now installed on macOS.
In the next chapter, we will install Python on Linux distributions.