2011-02-13 / 11:56 /

Next in the continuing series of Lest I Forget Again–in which I blog things that I should know but keep forgetting–installing the Python packaging tools.

As of February 2011 it looks like distribute, pip and virtualenv are the tools of choice.

Below is what I did for the combination of Windows 7, cygwin and the Windows (not-cygwin) binary release of Python 2.7. If you want real instructions you should check out The Hitchhiker’s Guide to Packaging (THGTP), especially the section on installation.

Install distribute

distribute includes setuptools and easy_install which you need to install pip. This is as easy as.

$ wget http://python-distribute.org/distribute_setup.py
$ python distribute_setup.py

This downloads the distribution archive to a temporary folder and installs it so you don’t even muddy up your cwd. You’ve now got the distribute in your Python Lib directory and easy_install.

Install pip

pip can be installed directly by easy_install.

$ easy_install pip

I extracted the tar by hand because I’d already downloaded it, but for future use easy_install is a better bet since it will get the latest version.

pip also comes built in to virtualenv (see below) but I prefer to install it standalone.

Install virtualenv (optional)

Several packages I need (e.g. cx_Oracle) don’t install via pip so virtualenv isn’t as handy for me. Still a nice idea for apps that you plan to ship, I used it for some pre-pyramid pylons stuff.

So cx_Oracle installs easiest as a binary package against a Python Windows binary. But since cmd is awful, I only ever run bash on cygwin. Unfortunately this combination of Win32 Python running on cygwin leads to a bug in virtualenv: it doesn’t install the activate script.

Last year I wrote a patch to go with the bug but this time I wanted to try the power of distributed source control so I made a BitBucket patch queue (read more about Patch Queues here).

$ hg qclone https://bitbucket.org/dgingrich/virtualenv-cygwin32
$ cd virtualenv-cygwin32
$ hg qpush -a
$ python setup.py install