Using pyenv with El Capitan

Even though now ships 2.7.10 with Mac OS X, I need to be able to switch versions and runtimes depending on project, so I rely on pyenv to do so without hassle.

The trick for getting it to work with El Capitan today is to not use the pyenv version from HomeBrew (currently 20150913) but to install the master branch from their GitHub repo.

That will bootstrap expat and other dependencies properly for both 2.7.10 and 3.5.

So here are the steps I took after upgrading my home machine:

# install the CLI tools
xcode-select --install

# get rid of the old pyenv and freshen up HomeBrew
brew uninstall pyenv
brew update; brew upgrade; brew cleanup

# Install the master branch of pyenv. Keep in mind that
# you may have to do some additional cleanup and setup 
# of env vars if you're migrating from HomeBrew's pyenv
git clone https://github.com/yyuu/pyenv.git ~/.pyenv

# note: I need brew's libxml2 and libxslt for installing 
# lxml later, but they are not needed for Python itself, 
# so you can skip this:
brew install libxml2 libxslt

pyenv install -v 2.7.10

As a side note, if you want to use uWSGI on your Mac be aware that PyPi hasn’t yet been updated to pick up this fix, so you might want to patch and build it manually (I only need to actually run it on Linux, so of course I just used instead).

This page is referenced in: