Tox and Pyenv – A Quickstart

I recently decided that I would try to help out with the Hyper Project. So far I have just changed one of the README’s to reflect the change on travis-ci build status to actually show the image now that Cory moved it from his personal account to an organization. Simple and easy.

I am developing on my MacBook, and for work at Addgene I use Python 2.7.11 because we’re not ready for 3.x yet due to some dependencies. I wanted to run the Tox tests on hyper-h2, and hpack but I had no py33, py34, py35, or pypy installed so everything failed except py27.

The solution to this was to use Pyenv and install everything as shims.

To do this I had to install pyenv which I did with homebrew.

$ brew install pyenv
$ echo 'eval "$(pyenv init -)"' >> ~/.zshrc # (This initializes pyenv when I start zsh.)

Once this was installed, I was able to use pyenv to install the other versions:

$ pyenv install 3.3.6
$ pyenv install 3.4.4
$ pyenv install 3.5.1
$ pyenv install pypy-5.0.0

Pyenv has features where you can install a python version into the directory you’re in, with pyenv local. This makes a .python-version in my current directory with the versions I specify. I’m not a big fan of this right now on my first pass, as I don’t want to have to add .python-versions into my global gitignore.

The other option is to use pyenv global which makes the versions available globally, I find this a lot nicer, because it puts all the version configuration in my user space, rather than my project space. To do this, I then ran

$ pyenv global 2.7.11 3.3.6 3.4.4 3.5.1 pypy-5.0.0

On my system python, outside of any virtual environments I install tox (pip install tox). I navigated back to the ‘hpack’ directory and ran tox. All the tests passed.


You may run into “The python zlib extension was not compiled” errors. To fix this, add the following CFLAGS variable in your shell:
CFLAGS="-I$(xcrun --show-sdk-path)/usr/include" before your pyenv install ... lines.

Leave a Reply

Your email address will not be published. Required fields are marked *