You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

如何通过Homebrew重新安装python@2?解决依赖工具执行报错

Fixing Homebrew Python@2 Missing Issue & Dependent Tool Errors

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:

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

    For example, if your GitHub username is Pauline, this would be:

    brew tap-new pauline/python2
    
  2. Extract 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>/python2
    
  3. Install Python@2 from your custom tap
    Now you can install Python@2 just like any other formula:

    brew install <your-username>/python2/python@2
    

    This will restore the /usr/local/opt/python@2/bin/python2.7 path 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:

  1. Access awscli’s isolated Python environment and upgrade jmespath:

    /usr/local/Cellar/awscli/2.0.0/libexec/bin/python -m pip install --upgrade jmespath
    

    This will replace the outdated jmespath version with one that fixes the is vs == 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

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.05.06 17:52:46