How to Install Python on a Mac
Get a Python you control, understand what PATH is doing, and isolate every project properly.
beginner9 min read
dev-setuppythonmacoshomebrewbeginners
Open Terminal on a brand-new Mac, type
python3, and something starts up — which is exactly why people get stuck an hour later. That interpreter belongs to Apple's command line tools, its version lags years behind, and installing packages into it is a reliable way to break other software on your machine. Meanwhile python with no 3 usually reports "command not found", because recent macOS releases removed the bundled Python 2 entirely. This guide installs a Python that you own, shows you how to confirm which one your shell is actually running, and sets up the per-project isolation that keeps the whole thing from rotting.iWhat you need
A Mac running macOS 13 or newer, your admin password, an internet connection, and about 25 minutes. Terminal is at Applications → Utilities → Terminal, or press Cmd+Space and type "terminal". You do not need Xcode.
macOS ships a
python3 at /usr/bin/python3 as part of the Xcode Command Line Tools. It exists so Apple's own scripts have an interpreter, not so you can build on it. Two things make it a bad foundation. First, the version is old — a stock machine commonly reports 3.9.6 while the current stable series is 3.14. Second, its packages live in a directory Apple owns, so a macOS update can replace the whole thing and silently take your installed libraries with it.macOS
$python3 --version
Run that before you change anything. If it prints
Python 3.9.6 or anything below 3.11, you are talking to Apple's copy. Leave it exactly where it is — removing it breaks system tooling. You are going to install a second Python alongside it and put that one first in your PATH.Homebrew is the package manager most Mac developers use, and it is the route worth recommending: one command installs Python, one command upgrades it later, and the same tool handles Node, Git, PostgreSQL, and everything else you will need. If you do not have it yet, follow How to Install and Use Homebrew on a Mac first, then come back.
macOS
$brew install python
The
python formula tracks the latest stable release, so this gets you the current 3.14 series. If a project pins you to a specific minor version, Homebrew keeps versioned formulae too — brew install python@3.13 installs 3.13 alongside without disturbing anything. Upgrading later is brew upgrade python, and that is the entire maintenance story.✓Where Homebrew puts it
On Apple Silicon, Homebrew installs under
/opt/homebrew and links python3 and pip3 into /opt/homebrew/bin. On Intel Macs it is /usr/local/bin. Either way, that directory has to come before /usr/bin in your PATH or your shell will keep finding Apple's copy.The alternative is the macOS installer from python.org/downloads. It is a signed
.pkg containing a universal2 build that runs natively on both Apple Silicon and Intel. Pick this route if you want one exact version and no package manager, or if you are following a course that assumes it.Installing from python.org
- 1Download the macOS 64-bit universal2 installer for the current 3.14 release.
- 2Open the .pkg and click through. It asks for your admin password because it writes to /Library.
- 3When it finishes, a Finder window opens showing the installed folder. Double-click Install Certificates.command — without this, HTTPS requests from Python fail with an SSL certificate verify error.
- 4Optionally double-click Update Shell Profile.command, which adds the new bin directory to your PATH.
- 5Close and reopen Terminal so the shell picks up the change.
This build lands in
/Library/Frameworks/Python.framework/Versions/3.14 and links commands into /usr/local/bin. The tradeoff versus Homebrew is upgrades: each new version is another manual download, and old versions stay installed until you delete the framework folder yourself.!Pick one route, not both
If you install via Homebrew and python.org, you now have two Pythons competing for the same command name and whichever bin directory sits earlier in PATH wins. That is the single most common source of "but I just installed that package" confusion. Choose one.
macOS
$which python3
This is the question that matters more than the version number. If it prints
/opt/homebrew/bin/python3 or /usr/local/bin/python3, your install is winning. If it still prints /usr/bin/python3, the install worked but your PATH did not change — reopen Terminal, and if that does not fix it, check your shell profile.bash
$ echo $PATH
/opt/homebrew/bin:/usr/local/bin:/usr/bin:/bin:/usr/sbin:/sbin
$ which python3
/opt/homebrew/bin/python3
$ python3 --version
Python 3.14.1PATH is a colon-separated search list, and the first match wins
PATH is just an ordered list of folders your shell searches when you type a command. It stops at the first hit. That single rule explains almost every install problem on this page. It also explains why bare
python may not exist: neither Homebrew nor python.org creates that symlink at the top level, deliberately, so that no script written for Python 2 silently runs under Python 3. Do not paper over it with an alias — you get a working python for free inside a virtual environment, which is the next section.Every modern Python includes
pip, the package installer. You will see it called both pip3 and python3 -m pip; prefer the second form. It runs pip from the interpreter you just named, which removes any doubt about which Python the package lands in.macOS
$python3 -m pip install --upgrade pip
✗Never run sudo pip install
It writes packages into directories the operating system manages, leaves root-owned files in your cache that later break normal installs, and can shadow a library some system tool depends on. A permissions error from pip is not a request for
sudo — it is a signal that you are installing outside a virtual environment.A virtual environment is a folder holding its own
site-packages directory and its own interpreter links. Activating it rewrites PATH for that shell session so python and pip point inside the folder. This is not an advanced technique to graduate into later — it is how you should work from your first project, because two projects will eventually want incompatible versions of the same library, and without isolation one of them loses.bash
mkdir ~/projects/first-python && cd ~/projects/first-python
python3 -m venv .venv
source .venv/bin/activate
# the prompt now starts with (.venv)
which python
# /Users/you/projects/first-python/.venv/bin/python
python -m pip install requests
python -m pip freeze > requirements.txt
deactivateThe whole loop, start to finish
The rules that keep this clean
- 1One environment per project, created inside the project folder and named .venv by convention.
- 2Add .venv to your .gitignore. You commit requirements.txt, never the environment itself.
- 3Activate with source .venv/bin/activate every time you open a new terminal in that project.
- 4Inside an active environment, plain python and pip are correct and safe to use.
- 5Rebuild an environment from a checkout with python3 -m venv .venv followed by python -m pip install -r requirements.txt.
- 6If an environment gets into a strange state, delete the .venv folder and recreate it. Nothing of value lives in there.
Virtual environments isolate packages, not interpreter versions. When you hit a project that requires 3.12 while your system Python is 3.14, that is what pyenv is for. It compiles multiple versions into your home directory and switches between them per shell or per directory. Until you actually have that problem, skip this section — pyenv adds a shim layer that makes install issues harder to debug.
macOS
$brew install pyenv
bash
echo 'export PYENV_ROOT="$HOME/.pyenv"' >> ~/.zshrc
echo '[[ -d $PYENV_ROOT/bin ]] && export PATH="$PYENV_ROOT/bin:$PATH"' >> ~/.zshrc
echo 'eval "$(pyenv init - zsh)"' >> ~/.zshrc
exec "$SHELL"Wire pyenv into zsh, then restart the shell
Day-to-day pyenv
- 1pyenv install -l lists every installable version. It is a long list; pipe it through grep.
- 2pyenv install 3.12.7 builds that version from source. Expect a few minutes of compiling.
- 3pyenv versions shows what you have and marks the active one with an asterisk.
- 4pyenv global 3.14.1 sets your default interpreter everywhere.
- 5pyenv local 3.12.7 writes a .python-version file so that one directory pins itself.
!pyenv still needs virtual environments
pyenv chooses which interpreter runs. It does nothing about package isolation. You still create a
.venv per project on top of the version pyenv selected.python
import sys
print("Running:", sys.executable)
print("Version:", sys.version.split()[0])hello.py
macOS
$python3 hello.py
Printing
sys.executable is worth remembering — it reports the exact interpreter running your code, which settles arguments that which cannot. In VS Code, open the project folder, press Cmd+Shift+P, run Python: Select Interpreter, and choose the one inside .venv. After that the Run button and the integrated terminal both use the right environment. How to Set Up VS Code covers the rest of that setup.Symptom, cause, fix
- 1python3 --version still shows 3.9.6. Your PATH has not picked up the new install. Close and reopen Terminal, then run which python3 to see which one is winning.
- 2command not found: python. Nothing links bare python at the system level, by design. Use python3, or activate a virtual environment where plain python exists.
- 3pip fails with error: externally-managed-environment. Homebrew's Python blocks installs into itself on purpose. Create and activate a virtual environment and install there.
- 4SSL: CERTIFICATE_VERIFY_FAILED when a script fetches a URL. You used the python.org installer and skipped Install Certificates.command. Run it from the installed Python folder in Applications.
- 5A package installs but the import fails. You installed with one interpreter and ran with another. Run python -m pip install inside the activated environment instead of bare pip3.
- 6source .venv/bin/activate says no such file. You are in the wrong directory, or venv creation failed. Run ls -a to check the folder exists, then recreate it.
- 7Permission denied installing a package. You are outside a virtual environment. Create one — do not reach for sudo.
- 8VS Code underlines an installed import in red. The editor is pointed at a different interpreter. Run Python: Select Interpreter and pick the .venv one.
Python is one piece of a working setup. If Homebrew is new to you, How to Install and Use Homebrew on a Mac makes every future install a one-liner, and How to Use the Command Line turns the terminal from a place you paste commands into a tool you can drive. Version control comes next with How to Use Git, since
requirements.txt only helps once the project is in a repository. Setting up a second machine on Windows? How to Install Python on Windows covers the parts that differ. When you want a sequence rather than a pile of tools, the Programming roadmap orders the language fundamentals so each one builds on the last.