Python is an adaptable programming language utilized for various applications such as web development, data analysis, automation, and beyond. macOS includes Python 2 by default; however, Python 2 has reached its end of life and is no longer maintained. It is recommended to install Python 3.
This manual offers a detailed procedure for installing Python 3 on macOS.
Looking for other platforms?
- Install Python on Windows
- Install Python on Ubuntu
Installing Python on Mac
Method 1: Using the Official Installer (Recommended)
Step 1: Download the Installer
- Open Safari or any web browser.
- Go to the official Python website: https://www.python.org/downloads/macos/**
- The website detects macOS and shows the latest stable version.
- Click the download button (for example, "Download Python 3.x.x").
- Open your Downloads folder and double-click the
.pkgfile. - Follow the installation wizard:
Step 2: Run the Installer
- Click "Continue"
- Agree to the license
- Choose the installation location (default is recommended)
- Click "Install"
- Enter your Mac password when prompted.
- Wait for the installation to complete.
- Open Terminal (Command + Space, type "Terminal", press Enter).
- Run the command:
Step 3: Verify Installation
python3 --version
You should see output like:
Python 3.12.2
- Check pip installation:
pip3 --version
Method 2: Using Homebrew
Homebrew serves as a widely-used package manager for macOS, simplifying the processes of software installation and management.
Step 1: Install Homebrew (if not already installed)
Open Terminal and run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
Step 2: Install Python with Homebrew
brew install python
This installs the latest Python 3 version.
Step 3: Verify Installation
python3 --version
pip3 --version
Step 4: Test Python in Terminal
- Open Terminal.
- Type:
python3
You will observe the Python interactive prompt (>>>).
- Execute a brief test:
print("Hello, World!")
Output:
Hello, World!
- Exit the shell with:
exit()
Setting Python 3 as Default (Optional)
By default, the python command still points to Python 2 on macOS. To use python instead of python3:
- Open Terminal.
- Edit your shell configuration file:
For bash (older Macs):
echo "alias python=python3" >> ~/.bash_profile
echo "alias pip=pip3" >> ~/.bash_profile
source ~/.bash_profile
For zsh (macOS Catalina and newer):
echo "alias python=python3" >> ~/.zshrc
echo "alias pip=pip3" >> ~/.zshrc
source ~/.zshrc
Now you can use python and pip instead of python3 and pip3.
Uninstalling Python (If Needed)
If you have set up Python via the official installer:
- Launch Terminal.
- Execute:
sudo rm -rf /Library/Frameworks/Python.framework/Versions/3.x
sudo rm -rf "/Applications/Python 3.x"
Replace 3.x with your Python version.
If you installed using Homebrew:
brew uninstall python
Conclusion
Python has been successfully installed on your macOS. You can now create scripts, install packages, and begin developing projects.
How to Install Python on Mac 1.FAQs
1. Does Mac come with Python?
Indeed, macOS comes with Python 2 pre-installed; however, Python 2 is no longer supported. It is advisable to install Python 3 for any new projects.
2. Which Python version should I install on Mac?
Obtain the most recent stable version of Python 3 from python.org or by utilizing Homebrew.
3. How do I check if Python is installed on Mac?
Open Terminal and run:
python3 --version
4. What is the difference between python and python3 commands?
-
pythontypically points to Python 2 (deprecated). -
python3points to Python 3 (recommended).
An alias can be established to utilize python with Python 3.
5. Should I use Homebrew or the official installer?
Both choices are viable:
- Official installer: More user-friendly for novices, provides a standard setup.
- Homebrew: More suitable for developers handling various tools, simplifies the updating process.
6. How do I update Python on Mac?
Utilizing the official installer: Acquire and set up the latest version from python.org.
Using Homebrew:
brew upgrade python