You can get any Python release, including the last Python 2, from the official download site:
https://www.python.org/downloads/release/python-2718/ → macOS 64-bit installer
Answer from mkrieger1 on Stack Overflowmacos - Install python@2 on Mac with M1 chip - Stack Overflow
Install python@2 on a Mac after python 2 support has ended on Homebrew - Stack Overflow
macos - How to reinstall python@2 from Homebrew? - Stack Overflow
macos - What is the best way to install python 2 on OS X? - Stack Overflow
You can get any Python release, including the last Python 2, from the official download site:
https://www.python.org/downloads/release/python-2718/ → macOS 64-bit installer
If, like me, you need it for development you should use PyEnv:
Here's a great tutorial: https://dev.to/jordicuevas/how-to-install-python2-in-a-macbook-m1-with-brew-bhi
TL;DR:
brew install pyenv
pyenv install 2.7.18
export PATH="$(pyenv root)/shims:${PATH}"
echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc
pyenv init
(Follow instructions provided. I had to add to ~/.zprofile and ~/.zshrc.)
Make sure you load the changes by running source ~/.zprofile and source ~/.zshrc.
pyenv shell 2.7.18
Now, the python command should target Python 2 in the shell/Terminal.
I could install 2.7.18 on M1.
brew install pyenv
pyenv install 2.7.18
Set the python version.
pyenv global 2.7.18
Export PATH if necessary.
export PATH="$(pyenv root)/shims:${PATH}"
Add if necessary.:
echo 'PATH=$(pyenv root)/shims:$PATH' >> ~/.zshrc
Sometimes you will get some errors like missing something if you are using rosetta then run:
arch -arm64 pyenv install 2.7.18
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
It seems that the homebrew staff really makes it as hard as possible to use Python 2.7 on macOS as they can.
- The linked
brew extractlink is really not helpful, you need to look for answers here about how to make your own tap from extracted sources. - The linked commit: 028f11f9e is wrong, as it contains the already deleted file.
- The
brew extractcommand doesn't even work correctly, because of the @ in the package name.
The solution is very simple though, you just need to download the latest known commit and install from that file:
cd ~
wget https://raw.githubusercontent.com/Homebrew/homebrew-core/86a44a0a552c673a05f11018459c9f5faae3becc/Formula/python@2.rb
brew install python@2.rb
rm python@2.rb
There might be a warning about this being "unstable", which I don't understand as a commit in a Git history is as stable as you can get.
Note from https://docs.brew.sh/Homebrew-and-Python: "Homebrew provides formulae to brew Python 3.y. A python@2 formula was provided until the end of 2019, at which point it was removed due to the Python 2 deprecation."
I use brew to install all my libraries/compilers/interpreters.
To install python try this:
brew install python
Then add Python's binaries directory to your $PATH in your ~/.profile:
export PATH=`brew --prefix python`/bin:$PATH
I'd recommend you to install pip, virtualenv and virtualenvwrapper to have better control over your environment too.
Have you tried ActivePython?
It includes a package manager (PyPM) that, by default, installs into your home directory (eg: ~/Library/Python/2.7). Main scripts get symlinked in /usr/local/bin; use the included pythonselect to set the active Python version.
You don't have to bother installing .dmg packages, as PyPM is a binary package manager ... therefore you can install non-pure Python packages like NumPy without having to compile things yourself.
ActivePython can use Apple's Tcl/Tk or, if installed, ActiveTcl.
A "simplest, most general approach" in your documentation could be:
- Install ActivePython 2.7
- Open Terminal and type
pypm-2.7 install matplotlib ipython
Few months back i installed python3 to learn coding, but after some time uninstalled the python3 by following steps given on the internet. Now when i write python --version, to check python 2 version, it shows :command not found which should be always present in the system. How do i get back python2 in system. If i install python3, will python2 also be automatically installed?
But i have not found any problems in my system yet due to python2, should i worry for future, or forget about it?