Install Python on macOS
Python tutorial · PySpark.in
Method 1 – Install Python using Official Installer
Step 1: Check if Python is already installed
Open Terminal:
- Press cmd+space
Type Terminal->press Enter
In Terminal run:
- python3 --version
If you see something like:
- python3.11.8
Python 3 is already installed.
If you see “command not found” or a very old version, follow the steps below.
Step 2: Download Python from the official website
- Open Safari or Chrome
- Go to: python.org
- Click on Downloads → Python 3.x.x for macOS
- This will download a file like:
python-3.xx.x-macosx.pkg
Step 3: Run the installer
- Open your Downloads folder
- Double-click the .pkg file
- A setup wizard opens. Follow these steps:
- Click Continue
- Read and click Agree on license
- Click Install
- Enter your Mac password if asked
- Wait for installation to finish
- At the end, you’ll see “Installation was successful”
Step 4: Verify Python installation
Open Terminal again and run:
- python3 --version
- You should see:
- Python 3.x.x
- Now check pip (Python’s package manager):
- pip3 --version
If you see a version, you’re ready to install packages.
Method 2 – Install Python using Homebrew (For Developers)
If you use Homebrew (or want to), this method is clean and dev-friendly.
Step 2: Install Homebrew (if not installed)
In Terminal, run:
- /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
- Follow on-screen instructions.
Once done, run: - brew --version
to confirm Homebrew is installed.
Step 3: Install Python with Homebrew
- brew install python
- Wait for the installation to finish.
Step 4: Verify Python
- python3 --version
- pip3 --version
Step 5: Make sure the correct Python is used
Sometimes macOS has an old system Python (/usr/bin/python).
To always use Python 3, use python3 and pip3 in commands.
Example:
- python3 my_script.py
- pip3 install numpy
Don’t try to remove the system Python. macOS needs it.
Step 6: Run your first Python program on Mac
Option 1: Run code directly in Terminal
In Terminal, type:
- python3
- You’ll see something like:
- Python 3.x.x (default, ...)
>>>
Now type:
- print("Hello from macOS!")
- Press Enter → you’ll see:
- Hello from macOS!
- Exit Python shell:
- exit()
- or press Ctrl + D.
Option 2: Run a .py file
- Create a file using TextEdit or VS Code or any editor.
- Save it as hello_mac.py (plain text, not rich text).
Put this inside:
- name = "Vishal"
- print("Hello,", name, "from macOS!")
- Now run in Terminal:
- cd /path/to/your/file
- python3 hello_mac.py
Output:
- Hello, Vishal, from macOS!
Step 7: Install useful Python packages
Use pip3 to install libraries:
- pip3 install numpy pandas matplotlib
- Check installed packages:
- pip3 list
Note:
Step | What to do | Command / Action |
|---|---|---|
1 | Open Terminal | Command + Space → “Terminal” |
2 | Check Python | python3 --version |
3 | Install via official installer | Download from python.org & run .pkg |
4 | Verify pip | pip3 --version |
5 | Run script | python3 hello_mac.py |
6 | Install packages | pip3 install numpy pandas |
More Python tutorials
- What is Python and Why is it used for Data Science and Data Engineering?
- How Does Python Work in the Backend? Internal Working of Python
- Top 30 Python Interview Questions for Data Science
- 3-Month Python Roadmap to Excel in Data Science and Machine Learning
- Python Data Types Explained – A Beginner’s Guide
- test
All tutorials · Try the free PySpark compiler · Practice challenges