You can use pyenv to install python with:

brew install pyenv
pyenv install 2.7.18

Optionally set it to your global default:

pyenv global 2.7.18

Nice article on why using pyenv is better than using brew to manage your python installation.

To make python binary available globally, add shims to PATH:

PATH=$(pyenv root)/shims:$PATH
Answer from donturner on Stack Overflow
🌐
The Hitchhiker's Guide to Python
docs.python-guide.org › starting › install › osx
Installing Python 2 on Mac OS X — The Hitchhiker's Guide to Python
export PATH="/usr/local/opt/python@2/libexec/bin:$PATH" Homebrew names the executable python2 so that you can still run the system Python via the executable python. $ python -V # Homebrew installed Python 3 interpreter (if installed) $ python2 ...
🌐
GitHub
gist.github.com › rcackerman › 3920028
Installing/updating Python 2.7 with Homebrew · GitHub
February 5, 2021 - Visit http://xquartz.macosforge.org/trac/wiki and download and install 2.7.5+. ... You may have to use sudo for this command. ... Mountain Lion will still use the system-installed python, in /usr/bin.
🌐
GitHub
gist.github.com › pithyless › 1208841
Install Python 2.7 (homebrew + pip + virtualenv) on Mac OS X Lion · GitHub
$ brew install readline sqlite gdbm $ brew install python --universal --framework $ python --version Python 2.7
🌐
Medium
medium.com › @liwp.stephen › install-python-2-7-on-mac-b09f05c43ab7
Install python 2.7 on mac - Stephen Lee - Medium
June 28, 2022 - But sometimes, there are still some tools we used daily still needs python 2.7. When search from network, we will find that install python 2.7 with brew with the command: brew install python@2 , but this command also failed right now.
🌐
DEV Community
dev.to › jordicuevas › how-to-install-python2-in-a-macbook-m1-with-brew-bhi
How to install python2 in a macbook M1 with brew - DEV Community
May 23, 2022 - First of all , you should have installed brew. ... After the installation of pyenv we can now proceed to install the required python version we need with the following command:
Find elsewhere
🌐
GitHub
gist.github.com › samuelbradshaw › 932d48ef1eff07e288e25e4355dbce5d
Installing Python 2 and 3 on macOS · GitHub
These instructions allow you to set up Python 2 and Python 3 side-by-side using pyenv. The instructions were tested on an Apple Silicon Mac, but the process on an Intel Mac should be similar. Homebrew is a popular package manager that makes it easy to install command line tools. If you don’t yet have Homebrew installed, instructions can be found here: https://brew.sh
🌐
Zaiste
zaiste.net › posts › installing-python-27-macos-homebrew
Installing python 2.7 on osx with homebrew · Zaiste Programming
April 30, 2012 - #MacOS · 2012-04-30 · 1 min read · Installing Python with Homebrew may have some quirks. Keep reading to see how to do it the right way. Let's start by updating Homebrew repository · brew update · then we install Python (2.7 in my case) brew install python ·
🌐
Tericcabrel
blog.tericcabrel.com › install-python2-on-macos
How to install Python 2 on Mac OS 12.3 and higher
December 21, 2022 - If you try to install Python 2 ... site. At the moment I'm writing this, the latest version is 2.7.18. Go to the download link and select the MacOS version....
🌐
Stack Abuse
stackabuse.com › install-python-on-mac-osx
Install Python on Mac OSX
December 21, 2015 - Now, keep in mind that Mac OSX (10.8) already comes with Python 2.7 pre-installed, so these instructions will only really be helpful if you need to upgrade versions or need a better way to manage installations (like with Homebrew).
🌐
Ahmad Awais
ahmadawais.com › home › python not found on macos | install python with brew | fix $path
Python not found on MacOS | Install Python with brew | Fix $PATH
June 12, 2023 - Now if you were to install the ... with lot less AI slop. try it free→ ... Not ideal, I know. Pre-requisite: Make sure brew is installed....
🌐
The Hitchhiker's Guide to Python
python-docs.readthedocs.io › en › latest › starting › install3 › osx.html
Installing Python 3 on Mac OS X — The Hitchhiker's Guide to Python
At this point, you have the system Python 2.7 available, potentially the Homebrew version of Python 2 installed, and the Homebrew version of Python 3 as well.
🌐
iBoysoft
iboysoft.com › home › how to tips › how to install python on mac in 2024 [two ways covered]
How to Install Python on Mac in 2024 [Two Ways Covered]
November 27, 2025 - In this article, we'll walk you through the different ways to install the latest version of Python onto a Mac in detail. OK, without further ado, let's get started! Actually, for many years, Python 2.7 is pre-installed on Mac (it is outdated and no longer maintained though).
🌐
freeCodeCamp
freecodecamp.org › news › python-version-on-mac-update
How to Install Python 3 on Mac – Brew Install Update Tutorial
April 6, 2021 - This version is included in macOS ... versions of macOS will not include Python 2.7. Instead, it is recommended that you transition to using 'python3' from within Terminal. Until Apple decides to set Python 3.x, as the default you're going to ...
Top answer
1 of 6
16

I have done this sort of thing in two ways - however both do not coexist with homebrew although I suspect there should be a way similar to the macports one.

General package manager

The first is using Macports as the package manager. There are separate ports for several python versions 2.x and 3.x currently 2.4, 2.5, 2.6, 2.7 and 3.1, 3.2, 3.3 3.4 and 3.5. For example to install 3.4 do sudo port install python34 There is also a python_select port that running it allows you to choose which version of python is run by /opt/bin/python. e,g, to select macports python 2.7 port select --set python python27

Each package manager needs to run as the only package manager otherwise it will be confused with unexpected different versions of libraries and executables on its paths.

From comments the similar homebrew way is given in https://stackoverflow.com/a/4158763/151019 Short answer seems to be brew switch the equivalent to port_select

Python version managers

The other way is install direct from python.org This will install a python into /usr/local/bin I think this installs a python and python3 executable. The issue with Homebrew is that it assumes that things in /usr/local are installed by it and so brew doctor will report these python.org pythons and libraries as issues and as this question shows also the frameworks in /Library will be problematic.

EDIT 8/2018 *** I would now suggest using conda either miniconda or anaconda. This is another package manager but based and mainly meant for python, it also gives the equivalent of python's virtual environments and pyenv (as per other answer) and so each project can be in a different python and different libraries (Macports only switches python version for all projects)

2 of 6
115

For Python in macOS, use pyenv:

brew install pyenv

To install a specific Python version, run:

pyenv install <version>

To select a version for every command run with the current folder:

pyenv local 3.5.0

Note that you must update PATH in your environment to find pyenv's python3 before any other:

PATH="~/.pyenv/shims:${PATH}"

With recent version of OSX(13.X) the path is moved to /etc/paths.d/ Add a file eg: pyenvpath to /etc/paths.d/pyenvpath Add the path to that file.

To list available versions:

pyenv versions

See https://gist.github.com/Bouke/11261620 for more information.