Python IDLE与HomeBrew更新后Python版本不一致问题咨询
python3 Shows Older Version After Homebrew Update? Hey there! I totally get the confusion—you’ve updated Python via Homebrew to 3.6.4_4, but your terminal still shows 3.5.2 when running python3 --version. Let’s break down why this is happening and how to fix it.
The Root Cause
This almost always comes down to your system’s PATH environment variable. When you run a command like python3, your Mac searches through directories listed in PATH in order—whichever directory has the matching executable first gets used.
- The Python you installed from the official website is likely in a directory that appears before Homebrew’s Python directory in your PATH.
- Homebrew typically installs Python in
/usr/local/bin(for Intel Macs) or/opt/homebrew/bin(for Apple Silicon Macs), but if your PATH prioritizes the older install’s location (like/Library/Frameworks/Python.framework/Versions/3.5/binor/usr/bin), that’s why you’re still seeing the 3.5.2 version.
Step-by-Step Fixes
1. Verify Current python3 Path
First, check exactly which python3 your terminal is using:
which python3
The output will show the full path to the executable (e.g., /Library/Frameworks/Python.framework/Versions/3.5/bin/python3), confirming it’s the old version.
2. Locate Homebrew’s Python Path
Next, find where Homebrew installed your updated Python:
brew info python
Look for lines like Executable:/usr/local/bin/python3.6—this is the path to your newer 3.6.4_4 version.
3. Adjust Your PATH to Prioritize Homebrew
You need to add Homebrew’s bin directory to the start of your PATH so it gets checked first.
If you’re using Zsh (default on macOS Catalina and later), edit your
~/.zshrcfile:nano ~/.zshrcAdd this line at the top:
# For Intel Macs export PATH="/usr/local/bin:$PATH" # For Apple Silicon Macs # export PATH="/opt/homebrew/bin:$PATH"Save the file (Ctrl+O, then Enter) and exit (Ctrl+X). Then apply the changes:
source ~/.zshrcIf you’re using Bash, edit
~/.bash_profileor~/.bashrcinstead, using the same PATH line, then runsource ~/.bash_profile.
4. Verify the Fix
Run python3 --version again—you should now see the Homebrew-updated 3.6.4_4 version.
Bonus: Use Homebrew’s Link Command (If Needed)
If adjusting PATH doesn’t work, you can force Homebrew to link its Python as the default:
brew link --force python
Note: Run brew link --dry-run python first to preview changes and avoid accidental conflicts.
内容的提问来源于stack exchange,提问作者user9141560

