Issue
Several newbie questions about coexistence of Homebrew and pyenv on MacOSX Yosemite. These are the things that I am still confused about after applying my level of google-fu to the subject. Sorry for the length, but I wanted to be as clear as possible.
First, some background. I used brew to install pyenv, then pyenv to install python2 and python3.
brew install pyenv
brew install pyenv-virtualenv
*I also added the necessary hooks into my profiles.*
pyenv install 2.7.10
pyenv install 3.4.3
pyenv rehash
pyenv global 2.7.10
??? Question (or clarification). If brew is using a python installed by pyenv, I assume that this is frowned on because brewed packages would be built with a dependency on something outside of brew (e.g. using pyenv to uninstall a python version could break brewed packages)? It appears that brew uses whichever python comes first in the PATH (currently pyenv's version for me)? However, in each of the below cases the shims are for “python” rather than “python3” (even for pyenv 3.4.3). Am I correct then in assuming that setting “pyenv shell 3.4.3” will make brew link python commands (that it assumes are for python2.x) to pyenv’s python 3.4.3, which I guess would tend to mess things up?
pyenv shell 2.7.10
brew --config
Python: /Users/anonymous/.pyenv/shims/python => /Users/anonymous/.pyenv/versions/2.7.10/bin/python2.7
pyenv shell 3.4.3
brew --config
Python: /Users/anonymous/.pyenv/shims/python => /Users/anonymous/.pyenv/versions/3.4.3/bin/python3.4
pyenv shell system
brew --config
Python: /Users/anonymous/.pyenv/shims/python => /usr/bin/python
??? Question. If using pyenv’s pythons to brew with is a bad idea, then should I also install brewed versions of python and python3, or would this conflict and cause problems in some way? My options seem to be either use the system python that came installed on my Mac, or use brew’s own pythons for all my brewing needs. In the first case, I could just make sure to call “pyenv shell system” before any brewing, or set some alias to automate this as others have suggested (alias brew="env PATH=${PATH//$(pyenv root)/shims:/} brew"). However, this means I have to use the rather outdated system python. If instead I were to also use brew to install python2 and python3, would this conflict with versions installed using pyenv in any way, or will brew’s pythons live happily completely separate from pyenv’s (I think this is true, but I want to double check before I try it)? Would this give me a setup where all my brewing used brew’s python or python3 (I assume I still need an alias such as that above to make sure pyenv’s versions are not found first in my PATH), and everything else outside of brew would use pyenv’s pythons? Is this a bad idea for any reason?
pyenv global system
*Add to profile:*
alias brew="env PATH=${PATH//$(pyenv root)\/shims:/} brew"
brew install python
brew install python3
??? For example, consider the scenario where I want to use brew to install boost-python with python3 bindings. Does this require a brewed python3 version, and will it subsequently work for a different pyenv version of python 3.x? If I only have pyenv’s versions installed, does the --with-python3 flag even work in this case? On the other hand, if I have brew’s python3 installed in addition to pyenv’s, I assume --with-python3 will link against brew’s python3 (with above alias). If so, will boost-python even be usable when called from a python session running pyenv’s version (not sure if this is more appropriate as a question about boost-python itself), or is this completely fine?
brew install boost
brew install boost-python --with-python3
??? Opinions regarding symlinks for brew that point to pyenv python's? Another post suggested symlinking pyenv's pythons so brew can find them. Besides the obvious caveat that brew now depends on python's that it does not itself manage, is there anything horribly wrong with this idea?
ln -s $(brew --cellar) ~/.pyenv/versions
Solution
A clarification: Homebrew uses system Python whenever it doesn't make a difference exactly which Python 2.7 it uses (which is pretty common). If you build something --with-python
, that will use the first Python in PATH, if that Python is Python 2.7. Otherwise, Homebrew will install and use Homebrew python.
I would not expect that you will find it necessary to install Homebrew's python and python3 but nothing bad should happen if you do. Note that if you use pip or easy_install to install a package that installs scripts (like ipython
), those scripts are written so that the package will always be invoked with the python against which it was installed. (You can always get around this behavior by running packages like python -m ipython
.) Otherwise, you can control which python you're using just by setting $PATH.
Building boost-python against whatever python 3.4 will work with any other python 3.4. It will probably not work with python 3.5. (This used to be more complicated, but it isn't, anymore!)
Symlinking your pyenv pythons into /usr/local shouldn't hurt but doesn't do anything except put them in $PATH; it won't help Homebrew find them otherwise.
Answered By - Tim Smith