![]() |
VOOZH | about |
Most modern versions of macOS (including macOS 12.3 and above) come with Python pre-installed, but it's usually an outdated Python 2.x version. Since Python 2 is no longer supported, itโs important to install the latest version (Python 3.x) to unlock its full power for programming, scripting, and development.
This guide provides a step-by-step tutorial to show all effective ways of installing and updating Python on macOS (MacBook Old Version and New Versions like M1, M2, M3 or M4), From checking your pre-installed version to downloading and updating the latest Python and setting up essential tools like IDEs and package managers, this guide will help you easily install Python on any MacBook Device.
Prerequisites
- A Running MacOS Laptop.
- Access to Macbook Administrative Privileges or Password.
Below are the quick and easy steps to Check the Pre-Installed Python Version on MacOS so that you can directly update the Python Latest version using Terminal and Homebrew.
Press Command + Space, type Terminal, and hit Enter.
Run the following command to check the installed Python 3 version:
python3 --versionPopup Appears: The xcode-select command requires the command line developer tools. Would you like to install the tools now?
When installing Homebrew (or sometimes Python directly), you might encounter a popup prompting you to install Command Line Developer Tools. These tools are required for many macOS development tasks, including Python installation.
Solution: When you see a popup asking you to install "Command Line Developer Tools" > Click on Install and wait for some time to Download the software. Ensure youโre connected to a stable Wi-Fi network.
Manually install the tools by running
xcode-select --installPython 3.x.x (Like in the below Image it shows Python 3.9.6), this means Python 3 is already installed. Now, we will Ensure the version matches the latest installed version (e.g., Python 3.13.x) after following further steps mentioned below in this guide.Troubleshooting:
- Command Not Found: If
python3doesnโt work, Python 3 is not installed. Continue with the installation.- Outdated Version: If an old version of Python 3 is installed, upgrade it using Homebrew (see Step 3).
Homebrew is a package manager for macOS that makes the software installation easy, including Python. In order to install Python on Mac using Brew, you first need to Intsall Homebrew on your Mac device. Follow the below easy steps in order to install Homebrew on Mac even if you have the pre-installed Python in your Mac Device:
Use the Shortcut key Command + Space, type Terminal, and hit Enter.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"IMPORTANT: What is "Checking for sudo access (which may request your password)"
Homebrew itself does not require
sudoto function. However, the installer does usesudoduring the initial setup to create the necessary installation directory at/opt/homebrewand configure its permissions. Additionally,sudois used to install and configure the Xcode Command Line Tools if they are not already installed. Once Homebrew is installed and set up, it no longer requiressudofor any of its operations.
Next steps:
Run these commands in your terminal to add Homebrew to your PATH:
echo >> /Users/userprofile/.zprofile
echo 'eval "$(/opt/homebrew/bin/brew shellenv)"' >> /Users/userprofile/.zprofile
eval "$(/opt/homebrew/bin/brew shellenv)"
In all the above given command Change "userprofile" with the actual username of your device.
Once installation is complete, verify Homebrew by running:
brew --versionYou should see a version number, confirming that Homebrew is installed.
Important: If you see the older Homebrew version installed, then run the following command to update Homebrew:
brew updateNow lets begin installing Python Latest version in your Mac Device, Using Homebrew is the simplest way to install Python 3 latest version, as it ensures you get the latest stable version.
Press Command + Space, type Terminal, and hit Enter.
This command will download and install Python 3 latest version along with pip, the Python package manager.
brew install pythonWait for the process to complete. You may see progress indicators as Homebrew downloads and installs dependencies.
python3.13 --versionIf installed correctly, youโll see the version number (e.g., Python 3.13.1).
pip installationpip3 --versionIf pip3 is installed, it will display its version.
Below are the most common Issues that arises when installing Python in your Mac, all these errors and issues looks difficult but they are very easy to fix in some quick steps:
Now run the following command, in order to fix any issue related to Homebrew not running in your terminal.
brew doctorNow after pressing the enter, it will show issues, If issues are reported, follow the suggested fixes.
Reinstall Python by copy and paste the following command in the terminal.
brew reinstall pythonTesting ensures that Python is set up correctly and ready for use.
Press Command + Space, type Terminal, and hit Enter.
python3Youโll see a >>> prompt, indicating Python is ready.
print("Hello, Python!")If you see Hello, Python!, Python is working correctly.
exit()If Python3 command doesnโt work after installation, you might need to add Python to your system PATH.
Use the shortcut key Command + Space, type Terminal, and hit Enter.
For macOS Catalina or later (default shell is Zsh):
nano ~/.zshrcFor older macOS versions (default shell is Bash):
nano ~/.bash_profileAdd the following line at the end of the file:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"Press Ctrl + O, then Enter, followed by Ctrl + X.
Now use the below command to reload the configuration to add Python to PATH on Mac
source ~/.zshrcNow verify the above steps tp preview the PATH Changes on Mac for Python Intsllation, If the version appears, Python 3 is successfully added to PATH.
python3 --versionVisit the official Python website and download the installer for macOS.
Open the .pkg file and follow the installation steps.
python3 --versionIf you still faces difficulty in installing the Python on Mac from the Python.Org Click here
While you can write Python scripts in any text editor, using an Integrated Development Environment (IDE) makes coding easier and more efficient.
GeeksforGeeks IDE
To expand Pythonโs functionality, you can install libraries using pip3.
Use Shortcut key to open Command + Space > Type Terminal > Hit Enter.
Click here to know all Python Libraries to understand each usecase.
pip3 install library_nameReplace library_name with the library you want to install, e.g., numpy.
Installing Python on your Mac opens the door of opportunities in programming, data analysis, and automation tasks. By following this step-by-step guide, you can seamlessly set up Python, ensuring compatibility with the latest tools and frameworks.
From web development and machine learning to scripting automation, Python empowers you to tackle a wide range of tasks with ease. With its growing popularity in data science, artificial intelligence, and software development, getting Python up and running on your Mac is a crucial step toward enhancing your technical skills and productivity.