MacOS High Sierra下brew管理的Python3消失且无法重装求助
Fixing Disappeared Python3 & Protecting Python2 After Homebrew Update on macOS High Sierra
Hey there, let's troubleshoot this Python + Homebrew issue you're facing—this kind of Python3 disappearance after a brew update is actually pretty common, so let's break it down step by step.
Step 1: Diagnose Your Current Python Environment
First, run these commands to get a clear picture of what's going on:
- Check where your default Python is located:
which python - Try locating Python3:
which python3 - List Python-related packages installed via Homebrew:
brew list | grep python - Verify installed versions:
python --version python3 --version
Step 2: Restore Your Missing Python3
Most likely, the issue is broken symlinks from the Homebrew update. Follow these steps to fix it:
- Clean up old Python cache and unused files first:
brew cleanup python - Try reinstalling Python3 explicitly:
brew install python3
If you get a message saying Python3 is already installed but you still can't access it, the symlinks are probably messed up. Fix that with:brew link --overwrite python3- If you hit a permission error, fix Homebrew's directory ownership first (avoid sudo unless absolutely necessary):
sudo chown -R $(whoami) $(brew --prefix)
Then re-run the link command.
- If you hit a permission error, fix Homebrew's directory ownership first (avoid sudo unless absolutely necessary):
Step 3: Keep Your Python2 Safe During Brew Operations
You don't need to worry about losing access to Python2 when running brew upgrade python—here's why:
- The Python2 that came pre-installed with macOS High Sierra lives in
/usr/bin/python, which is part of the system's core files. Homebrew never modifies or deletes files in system directories; it only manages packages in its own directory (usually/usr/local/bin). - Modern Homebrew's
pythonformula defaults to Python3. If you ever need to install a separate Homebrew-managed Python2, you can usebrew install python@2(note: this package is archived, so you might need to runbrew tap homebrew/corefirst to access it). But the safest way to use your original Python2 is to call it explicitly with/usr/bin/pythoninstead of justpython, which avoids conflicts with Homebrew's Python3.
Bonus: Avoid Future Version Conflicts
If you regularly switch between Python versions, using pyenv is a great way to manage them without messing with system or Homebrew defaults:
brew install pyenv # Install specific versions you need pyenv install 2.7.18 pyenv install 3.11.x # Replace with your preferred Python3 version # Set a default global version pyenv global 3.11.x
内容的提问来源于stack exchange,提问作者Daksh Shah
相关产品推荐
相关产品推荐

