Virtualenv with different python version

It's possible to create a Python environment with a different Python version.
Let's say you have installed Python 2.7 and you want to be able to run a project in Python 2.6.

First install Python 2.6:

$ port install python26

Then create an environment like this:

$ mkvirtualenv --python=/usr/bin/python2.6 yournewenv

You can check to see you're using a different Python version in your environemnt by typing:

(yournewenv) $ python --version

This should return Python 2.6.8


In case you're running OS X El Capitan and you want Python3 to run in virtualenvs:

First, update your current python like so:

$ brew install python

Then, install Python3 like so:

$ brew install python3

Then, you can upgrade virtualenvwrapper systemwide like so:

$ pip install virtualenvwrapper --upgrade

And then you can create Python3 virtualenvs like so:

$ mkvirtualenv -p /usr/local/bin/python3 py3test