4

after I tried to uninstall python 2.7

% brew uninstall python@2     

I cannot reinstall back python 2.7 on my mac (big sur)

% brew install python@2                                    
Error: 
  homebrew-core is a shallow clone.
  homebrew-cask is a shallow clone.
To `brew update`, first run:
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-core fetch --unshallow
  git -C /usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask fetch --unshallow
This restriction has been made on GitHub's request because updating shallow
clones is an extremely expensive operation due to the tree layout and traffic of
Homebrew/homebrew-core and Homebrew/homebrew-cask. We don't do this for you
automatically to avoid repeatedly performing an expensive unshallow operation in
CI systems (which should instead be fixed to not use shallow clones). Sorry for
the inconvenience!
==> Searching for similarly named formulae...
Error: No similarly named formulae found.
Error: No available formula or cask with the name "python@2".
==> Searching for a previously deleted formula (in the last month)...
Warning: homebrew/core is shallow clone. To get complete history run:
  git -C "$(brew --repo homebrew/core)" fetch --unshallow

Error: No previously deleted formula found.
==> Searching taps on GitHub...
Error: No formulae found in taps.

UPDATE: I notice this as well

% pwd
/Library/Frameworks/Python.framework/Versions
% ls -al
total 0
drwxrwxr-x   6 root  wheel  192 Jan 11 14:18 .
drwxr-xr-x   6 root  wheel  192 Jan 11 14:18 ..
drwxrwxr-x  10 root  admin  320 Nov  8  2017 3.6
drwxrwxr-x  10 root  admin  320 Jan  2 18:24 3.8
drwxrwxr-x  11 root  admin  352 Jan 11 14:18 3.9
lrwxr-xr-x   1 root  wheel    3 Jan 11 14:18 Current -> 3.9
% python -V  
Python 2.7.16
% python3 -V
Python 3.9.1

in another location

% ls -al
total 0
drwxr-xr-x   7 root  wheel  224 Jan  1  2020 .
drwxr-xr-x   5 root  wheel  160 Jan  1  2020 ..
lrwxr-xr-x   1 root  wheel    3 Jan  1  2020 2.3 -> 2.7
lrwxr-xr-x   1 root  wheel    3 Jan  1  2020 2.5 -> 2.7
lrwxr-xr-x   1 root  wheel    3 Jan  1  2020 2.6 -> 2.7
drwxr-xr-x  11 root  wheel  352 Jan  1  2020 2.7
lrwxr-xr-x   1 root  wheel    3 Jan  1  2020 Current -> 2.7
% pwd
/System/Library/Frameworks/Python.framework/Versions

There seems to be 2 installed locations for python in Mac

/Library/Frameworks/Python.framework/Versions
/System/Library/Frameworks/Python.framework/Versions

How can I reinstall python 2.7 or say reinstate it if its unlinked ?

Axil
  • 3,606
  • 10
  • 62
  • 136
  • I'd suggest using pyenv for this rather than homebrew, assuming you actually _need_ Python2 newer than the system python – OneCricketeer Jan 11 '21 at 23:47
  • https://stackoverflow.com/questions/65662275/pyenv-versions-doesnt-show-anything-after-installing-other-version-of-python-on <-- I have tried, this is my other post related to pyenv – Axil Jan 12 '21 at 00:05

1 Answers1

4

It gets harder and harder to use Python 2.7. Here are the 3 last methods I used, only the last works now.

Miniconda2, stopped working

Until recently I was using Miniconda2 for Python 2.7, but they also just stopped supporting Python 2.7.

Old version of a Brew formula, stopped working

You can still download and old version of a Brew formula and install Python 2.7.

cd ~

wget https://raw.githubusercontent.com/Homebrew/homebrew-core/86a44a0a552c673a05f11018459c9f5faae3becc/Formula/python@2.rb

brew install python@2.rb

Native macOS Python 2.7.16 with pip and virtual environment, still working

I was able to setup a working Python 2.7 environment in this way by reusing the native Python 2.7.16

  • Install pip manually
  • Setup a virtual environment
  • Install dependencies with pip in virtual environment

Here are the install steps:

wget https://bootstrap.pypa.io/pip/2.7/get-pip.py
python get-pip.py
pip install virtualenv
~/Library/Python/2.7/bin/pip  install virtualenv
virtualenv --python=/usr/bin/python venv
source venv/bin/activate

This is still working, but I am now strongly motivated to port to Python 3.x.

Sami Badawi
  • 977
  • 1
  • 10
  • 22
  • 1
    I'ved completely formatted the mac. its really a pain after so many years. – Axil Feb 07 '21 at 23:17
  • It doesn't work anymore: ```curl: (22) The requested URL returned error: 404 Error: Failed to download resource "python@2_bottle_manifest" Download failed: https://ghcr.io/v2/homebrew/core/python/2/manifests/2.7.17_1 ``` – Quentin Jun 19 '21 at 17:12
  • @Quentin I updated my post with the last remaining method that I got working. – Sami Badawi Jun 23 '21 at 05:37