Issue
I had previously installed python 2.7 and python 3 with homebrew.
I added these versions to pyenv
ln -s $(brew --cellar python)/* ~/.pyenv/versions
ln -s $(brew --cellar python@2)/* ~/.pyenv/versions
When I set the global version with pyenv global 3.6.5
, I get the following error on running this command
➜ python --version
pyenv: python: command not found
The `python' command exists in these Python versions:
2.7.15
I'd like to setup so that python
command points to the global version.
Solution
Homebrew's python
formula is Python 3. To avoid breaking applications which expect the python
command to run Python 2, brew install python
does not add a python
command, only python3
. This is included in the caveats, visible in brew info python
:
Python has been installed as /usr/local/bin/python3
Unversioned symlinks
python
,python-config
,pip
etc. pointing topython3
,python3-config
,pip3
etc., respectively, have been installed into /usr/local/opt/python/libexec/bin
When using homebrew only, it's easy to get python
to point to Python 3 by adding a line like this to one's shell configuration:
export PATH="/usr/local/opt/python/libexec/bin:$PATH"
So, one solution could be to link pyenv
to that directory instead:
ln -s $(brew --prefix)/opt/python/libexec/bin ~/.pyenv/versions/3-brew
This would make python
work. However, it means that python3.6
won't work, because that executable lives back in $(brew --cellar python)/3.6.5
, so it's not a complete solution. I haven't yet figured out anything that preserves both behaviors without manually adding symlinks to Homebrew's installed Python.
Answered By - ravron Answer Checked By - Marilyn (WPSolving Volunteer)