python及python3命令未指向pyenv全局版本的问题求助
pyenv: python: command not found When Using Homebrew-Installed Python Versions Let's break down why this error pops up and how to fix it quickly:
Why the Error Happens
When you symlinked your Homebrew-installed Python versions into pyenv's versions directory, you might have missed a key detail: Homebrew names Python 3's executable python3 instead of python (unlike Python 2, which uses python by default). Pyenv looks for a python executable in your active global version's bin folder—since 3.6.5 doesn't have one, it checks other installed versions and throws the error pointing to 2.7.15.
Step-by-Step Fix
Confirm the missing executable
First, check that your 3.6.5 version only haspython3:ls ~/.pyenv/versions/3.6.5/binYou’ll see
python3listed, but nopythonentry.Create a symlink for
pythonin the 3.6.5 directory
Linkpythontopython3so pyenv can locate the command:ln -s ~/.pyenv/versions/3.6.5/bin/python3 ~/.pyenv/versions/3.6.5/bin/pythonVerify the fix
Run this to confirm the global version is now recognized:python --versionIt should output
Python 3.6.5.
Bonus: Double-Check Pyenv Initialization
If the fix above doesn’t work, make sure pyenv's shims are properly loaded in your shell. Check that ~/.pyenv/shims is at the start of your PATH:
echo $PATH
If it’s not, add these lines to your shell config file (e.g., ~/.bashrc, ~/.zshrc):
export PATH="$HOME/.pyenv/shims:$PATH" eval "$(pyenv init -)"
Then restart your shell or run source ~/.bashrc (or your specific config file) to apply the changes.
内容的提问来源于stack exchange,提问作者arjunurs

