I recently worked on a legacy codebase that requires Python2, which has been deprecated for some time and is no longer available via homebrew.
Using this Stack Overflow thread I was able to resolve the issue as below. Note that the “pyenv global” command might interfere with with your Python3 environment.
The Error
➜ yarn install --check-files
gyp verb command configure []
gyp verb check python checking for Python executable "python2" in the PATH
gyp verb `which` failed Error: not found: python2
➜ which python
python not found
➜ which python2
python2 not found
The Fix
➜ brew install pyenv
➜ pyenv install 2.7.18
➜ pyenv global 2.7.18
➜ PATH=$(pyenv root)/shims:$PATH
➜ which python2
/Users/user/.pyenv/shims/python2
➜ yarn install --check-files
yarn install v1.22.19
...
Done in 10.26s
Add to ~/.bashrc or ~/.zshrc to make available in future shell sessions:
# make python exe available globally
PATH=$(pyenv root)/shims:$PATH