How can I make homebrew's python and pyenv live together?

You can install pyenv in your home directory (as described in pyenv's installation guide), and then create a symlink at ~/.pyenv/versions to $(brew --cellar)/python:

ln -s $(brew --cellar python)/* ~/.pyenv/versions/

The way Homebrew works nowadays, this will pick up both 2.x and 3.x.


A handy function to relink versions:

pyenv-brew-relink() {
  rm -f "$HOME/.pyenv/versions/*-brew"

  for i in $(brew --cellar python)/*; do
    ln -s --force $i $HOME/.pyenv/versions/${i##/*/}-brew;
  done

  for i in $(brew --cellar python@2)/*; do
    ln -s --force $i $HOME/.pyenv/versions/${i##/*/}-brew;
  done
}

Well if you want the pyenv pythons and homebrew pythons to live together you need to make the name of the homebrew pythons something other than the version. Otherwise they will clash with the directory names that pyenv uses. For example, if you want to install pyenv python 2.7.11 and homebrew python 2.7.11 you could do something like this.

for i in `ls $(brew --cellar python)/`; do 
  ln -s $(brew --cellar python)/$i $HOME/.pyenv/versions/$i-brew; 
done

for i in `ls $(brew --cellar python3)/`; do 
  ln -s $(brew --cellar python)/$i $HOME/.pyenv/versions/$i-brew; 
done

Essentially this will create a directory in $HOME/.pyenv/versions appended with '-brew' so that it won't clash with the pyenv pythons.