如何通过Homebrew重新安装python@2?解决依赖工具执行报错
Hey there, I’ve dealt with this exact scenario when Python 2.7 was removed from Homebrew’s core repo, so let’s work through this together.
Step 1: Reinstall Python@2 Using brew extract
Since Python@2 was deleted from Homebrew core, you’ll need to create your own tap (a custom Homebrew formula repository) to host the old Python@2 formula. Here’s how to do it:
Create a new custom tap
Replace<your-username>with your GitHub username (you don’t even need to create the repo on GitHub first—Homebrew handles the local setup):brew tap-new <your-username>/python2For example, if your GitHub username is Pauline, this would be:
brew tap-new pauline/python2Extract the Python@2 formula to your tap
Run this command to pull the deleted Python@2 formula from Homebrew’s git history into your custom tap:brew extract python@2 <your-username>/python2Install Python@2 from your custom tap
Now you can install Python@2 just like any other formula:brew install <your-username>/python2/python@2This will restore the
/usr/local/opt/python@2/bin/python2.7path that your tools are looking for.
Step 2: Fix Dependent Tools (awscli, sshuttle, letsencrypt)
For awscli
The SyntaxWarnings you’re seeing are from the jmespath library bundled with awscli v2—they’re harmless but annoying. To fix them:
Access awscli’s isolated Python environment and upgrade jmespath:
/usr/local/Cellar/awscli/2.0.0/libexec/bin/python -m pip install --upgrade jmespathThis will replace the outdated jmespath version with one that fixes the
isvs==syntax issue.Note: awscli v2 uses Python 3 natively, so once you fix this warning, you shouldn’t need Python@2 for awscli anymore. But if you still have older scripts tied to awscli v1 (which required Python 2), you can install v1 via your custom tap or use a virtual environment.
For sshuttle, letsencrypt, and other Python@2-dependent tools
Once Python@2 is reinstalled, simply reinstall these tools to re-link them to the correct Python path:
brew reinstall sshuttle letsencrypt
This will update their shebang lines to point to your newly installed /usr/local/opt/python@2/bin/python2.7.
A Quick Note on Python 2 EOL
While this fixes your immediate issue, keep in mind Python 2 reached end-of-life in 2020. Whenever possible, migrate to Python 3 versions of your tools:
- awscli v2 is fully Python 3 compatible (you’re already using it!)
- sshuttle has Python 3 support in newer versions
- Let’s Encrypt’s Certbot now uses Python 3 by default
Migrating will save you from future compatibility headaches.
内容的提问来源于stack exchange,提问作者Pauline

