How to Reinstall Python@2 from Homebrew

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.

  1. 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.
  2. The linked commit: 028f11f9e is wrong, as it contains the already deleted file.
  3. The brew extract command 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.

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. 1

Usage:

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:

Warning: python@2 is keg-only and must be linked with --force Note that doing so can interfere with building software.

See the accepted answer to this SO question for some details on that.

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



Leave a reply



Submit