How to reinstall python@2 from Homebrew?
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 extract
link 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 extract
command doesn't even work correctly, because of the @ in the package name.
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. Install python@2 on a Mac after python 2 support has ended on Homebrew
I was able to find the exact same question -- Brew - reinstalling python@2. Unfortunately I can't raise the duplicate flag again so I'll duplicate the answer:
brew install https://raw.githubusercontent.com/Homebrew/homebrew-core/86a44a0a552c673a05f11018459c9f5faae3becc/Formula/python@2.rb
How to install Python 2 on macOS 12.3+
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
How can I use Homebrew to install both Python 2 and 3 on Mac?
I would use pyenv You can install it:
$ brew install pyenv
To enable pyenv in your Bash shell, you need to run:$ eval "$(pyenv init -)"
To do this automatically for Bash upon startup, add that line to your ~/.bash_profile
. 1Usage:
Once you have installed pyenv and activated it, you can install different versions of python and choose which one you can use. Example:
$ pyenv install 2.7.5
You can check the versions you have installed with:$ pyenv versions
And you can switch between python versions with the command:$ pyenv global 3.3.1
Also you can set a python version for the current directory with:$ pyenv local 3.5.2
You can check by running python --version
:$ python --version
Python 3.5.2
1 Homebrew used to instruct you to do this upon installation of pyenv, but the message was removed. For Zsh and other shells, the precise steps may be different.
How to run Python2 after Homebrew Update?
You're missing the symbolic link that Homebrew makes from the Cellar to the actual bin directory on your path.
Use:
brew link python2
to fix that.You may run into a warning:
See the accepted answer to this SO question for some details on that.Warning: python@2 is keg-only and must be linked with --force Note that doing so can interfere with building software.
In most case, you can then safely use
brew link --force python2
if you're not planning building your own libraries that require the source code (libpython.so
and Python.h
) for Python 2.If you do require the source code, you'll need to provide the include paths and library paths to e.g.
/usr/local/Cellar/python/2.7.14_3/Frameworks/Python.framework/Versions/2.7/include/python2.7
and /usr/local/Cellar/python/2.7.14_3/Frameworks/Python.framework/Versions/2.7/lib/
. But that's a different topic or question.To use pip for Homebrew's Python 2, best to use is
python2 -m pip <command>
Then you can clearly see what Python your pip
command goes with, and keep it apart from Python 3 (which would be python3 -m pip
).Note
If you have Homebrew problems, first cause of action is to run
brew doctor
The error messages are usually quite helpful to fix at some of the problems.
Related Topics
Lookup Values by Corresponding Column Header in Pandas 1.2.0 or Newer
How to Multiply Individual Elements of a List with a Number
"Overflowerror: Python Int Too Large to Convert to C Long" on Windows But Not MAC
Method Not Allowed Flask Error 405
How to Use Python-Docx to Replace Text in a Word Document and Save
Adding a Y-Axis Label to Secondary Y-Axis in Matplotlib
Tuple Unpacking Order Changes Values Assigned
Define CSS Class in Django Forms
Representing and Solving a Maze Given an Image
Should All Python Classes Extend Object
Setting Variables with Exec Inside a Function
Is There a Simple Process-Based Parallel Map for Python
How to Flatten a Pandas Dataframe with Some Columns as JSON
How to Crop the Internal Area of a Contour
Python Sorting by Multiple Criteria