Trying Python virtualenvwrapper
I’ve upgraded my MacBook recently. This included a clean Mac OS 10.6 installation. Before making everything “dirty” with “eggs” and “gems”, I decided to organize the development environments from the very beginning.
Python
Let’s start with Python. Mac OS 10.6 comes with python 2.6 preloaded. I wanted to install Python 2.7 and 3.2. This was the easiest part:
- Go to http://www.python.org/download/
- Grab the version/s you want to install. They’re packaged as dmg files
- I used the 64 bit version. But this depend on your Mac OS installation.
These versions will be installed in the /Library/Frameworks/Python.framework/Versions folder. With a link to the “Current version” and a bunch of executable links at /usr/local/bin.
The installations will modify your $HOME/.bash_profile. They’ll add their paths, so after installing 2.7 and 3.2. The first python executable will be the 2.7 version. My personal preference was to disable them and wait till I setup virtualenv.
Setting up virtualenv
In order to use clean environments it’s time to install: virtualenv and virtualenvwrapper. This will allow you to build virtual python environments without installing packages on the system/root python.
My personal preference was to install pip, and then virtualenv & virtualenvwrapper in the pre-installed python 2.6. I used sudo to have them available in all environments, but I believe you can install them on your $HOME.
To show a bit how this works, let’s run the setup directly on the shell.
Initialize virtualenv
plakaki:~ alff$ export WORKON_HOME=~/PythonEnvs plakaki:~ alff$ mkdir -p $WORKON_HOME plakaki:~ alff$ source /usr/local/bin/virtualenvwrapper.sh
Create an environment for daily work
plakaki:bin alff$ mkvirtualenv -p python2.7 daily Running virtualenv with interpreter /usr/local/bin/python2.7 New python executable in daily/bin/python Installing setuptools............................done. virtualenvwrapper.user_scripts creating /Users/alff/PythonEnvs/daily/bin/predeactivate virtualenvwrapper.user_scripts creating /Users/alff/PythonEnvs/daily/bin/postdeactivate virtualenvwrapper.user_scripts creating /Users/alff/PythonEnvs/daily/bin/preactivate virtualenvwrapper.user_scripts creating /Users/alff/PythonEnvs/daily/bin/postactivate virtualenvwrapper.user_scripts creating /Users/alff/PythonEnvs/daily/bin/get_env_details (daily)plakaki:bin alff$ python -V Python 2.7.1
Working and active
Changing environments
(daily)plakaki:~ alff$ deactivate plakaki:~ alff$ workon daily (daily)plakaki:~ alff$ python -V Python 2.7.1
Run it in every terminal
I added the following extra lines in my .bash_profile:
WORKON_HOME=~/PythonEnvs export WORKON_HOME source /usr/local/bin/virtualenvwrapper.sh
Nothing else to add. Now it’s time to keep the code flowing

Leave a Reply