Mac多Python版本管理异常:调用python3.6却返回2.7版本求助
It looks like your /usr/local/bin/python3.6 is either an alias pointing to Anaconda's Python 2.7, or a broken symlink. Let's fix this step by step:
Step 1: Check for Aliases or Shell Functions
First, run this command to see if your shell has an alias overriding python3.6:
type -a python3.6
If you see output like:
python3.6 is aliased to '/Users/User/anaconda/bin/python'
You'll need to remove that alias. Look for lines like alias python3.6='/Users/User/anaconda/bin/python' in your shell config files (.bashrc, .zshrc, .bash_profile, etc.), delete them, then restart your terminal or run source ~/.zshrc (or the relevant file) to apply changes.
Step 2: Inspect the Symlink
If there's no alias, check what /usr/local/bin/python3.6 actually points to:
ls -l /usr/local/bin/python3.6
If the output shows it's linked to Anaconda's Python (e.g., -> /Users/User/anaconda/bin/python), that's the problem. We need to relink it to your actual Python 3.6 installation.
Step 3: Fix the Symlink
First, remove the incorrect symlink:
sudo rm /usr/local/bin/python3.6
Then create a new symlink pointing to your real Python 3.6 executable. Based on your PATH, it should be in /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6:
sudo ln -s /Library/Frameworks/Python.framework/Versions/3.6/bin/python3.6 /usr/local/bin/python3.6
Step 4: Verify the Fix
Run the command again to confirm it works:
/usr/local/bin/python3.6 --version
You should now see Python 3.6.x instead of 2.7.14.
Optional: Set Python 3.6 as Default (If Needed)
If you want python to point to 3.6 by default, adjust your PATH in your shell config file to put the Python 3.6 directory before Anaconda's. For example, add this line to .zshrc or .bashrc:
export PATH="/Library/Frameworks/Python.framework/Versions/3.6/bin:$PATH"
Then restart your terminal or run source ~/.zshrc to apply.
内容的提问来源于stack exchange,提问作者NT_

