Mike Barkas

Software Technologies

Mike Barkas

Mike Barkas

Software Technologies

Running Different Versions of Python

October 26, 2016

Your operating system comes with a specific version of Python. At the time of this writing, the version is probably around 2.7.

It is best to not change this version as some system links my depend on this version of Python. If you move or edit your default version, you may cause other programs in your system to not work properly.

Homebrew

With brew you can install Python version 2 and 3, but may only be able to get 3.3 or whatever is available to tap at the time. Many times brew version will be not the most current. Also, when installing with brew you are installing the version system-wide and this makes it difficult to easily switch interpreter types and versions for different project requirements.

There are tools and utilities to help with installing and running different versions of Python. I had issues getting them to work properly for me, and sometimes they were too complicated. I have tried pythonz and also pyenv. Using these tools along with virtualenvwrapper I had the most success with pyenv.

For my Python version management, I combine two tools, pyenv and virtualenvwrapper.

Pyenv

I use pyenv to download and update the different versions of Python interpreters and that is all I use it for. Setting up pyenv-virtualenvwrapper and its configuration was a little too involved.

After downloading a few versions of Python interpreters, I will have the following directories:

~/.pyenv/versions/3.4.3

~/.pyenv/versions/pypy-4.0.0

In each of the above directories there will be a bin directory containing the executable.

Virtualenvwrapper

Now I can use virtualenvwrapper and the above directory with the -p flag to specify the Python version.

I create a different virtualenv for each Python version I need for a project.

Examples:

mkproject -p ~/.pyenv/versions/3.4.3/bin/python3.4 ENVNAME

mkproject -p ~/.pyenv/versions/pypy-4.0.0/bin/pypy ENVNAME

Summary

I like to use pyenv to download and maintain different Python interpreters and their versions.

I then use virtualenvwraper to create virtualenvs with the downloaded interpreters.