My initial patch was needlessly complicated, so I've attached a better version. There are two basic changes I have made:
* I try to import setuptools as well to make sure all of setuptools is available. This is required because Ubuntu defaults to only install pkg_resources.
* I always reload sys.modules('pkg_resources'). This is needed because ez['use_setuptools'](..) may import the wrong pkg_resources.