After switching to python 3.4.3 from 2.7.9 (which was quite simple), I often wish to test some of my scripts with python 2.7.9 before sharing them with colleagues. I am using a OSX yosemite platform with everything compiled from homebrew.
The situation was quite ugly (setting PATH
es and PYTHONPATH
at each step) - until I discovered pyenv which does this very easily and is easily installed using homebrew. So far, so good.
However, now that I am using this version of python, it does not necessarily play well with that of homebrew. Moreover, I found that I could switch back to the system's python, and more generally that pyenv could access that:
$ pyenv versions system 2.7.9 * 3.4.3 (set by /usr/local/var/pyenv/version)
but how could I also add entries for the python
s compiled by homebrew?
pyenv is a wonderful tool for managing multiple Python versions. Even if you already have Python installed on your system, it is worth having pyenv installed so that you can easily try out new language features or help contribute to a project that is on a different version of Python.
When using pyenv , you should be able to set your 'local' version in the directory you are working in, and then pip will rely on this version.
PROTIP: When pyenv is installed, a folder ~/. pyenv is created under your user $HOME folder. Within the shims folder are every Python command in every installed version of Python—python, pip, etc.
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 }
If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!
Donate Us With