[Distutils] [issue95] [PATCH] ez_setup.py fails when pkg_resources is installed but setuptools is not

Zooko O'Whielacronx setuptools at bugs.python.org
Thu Nov 12 22:48:09 CET 2009


New submission from Zooko O'Whielacronx <zooko at zooko.com>:

This just happened on Ubuntu Karmic:

HACL zooko-desktop:/sdb/zooko/ecometry2rabbit/ecometry2rabbit$ /usr/bin/python
setup.py test
Traceback (most recent call last):
  File "setup.py", line 2, in <module>
    use_setuptools()
  File "/sdb/zooko/ecometry2rabbit/ecometry2rabbit/ez_setup.py", line 116, in
use_setuptools
    if not setuptools_is_new_enough(min_version):
  File "/sdb/zooko/ecometry2rabbit/ecometry2rabbit/ez_setup.py", line 88, in
setuptools_is_new_enough
    pkg_resources.require('setuptools >= %s' % (required_version,))
  File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 626, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 524, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
pkg_resources.DistributionNotFound: setuptools>=0.6c7

As you can see from the following, the pkg_resources module is importable even
though setuptools is not installed:

HACL zooko-desktop:/sdb/zooko/ecometry2rabbit/ecometry2rabbit$ /usr/bin/python
-c 'import pkg_resources;print pkg_resources;print
pkg_resources.require("setuptools")'
<module 'pkg_resources' from '/usr/lib/python2.6/dist-packages/pkg_resources.pyc'>
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 626, in require
    needed = self.resolve(parse_requirements(requirements))
  File "/usr/lib/python2.6/dist-packages/pkg_resources.py", line 524, in resolve
    raise DistributionNotFound(req)  # XXX put more info here
pkg_resources.DistributionNotFound: setuptools

This is because Debian and Ubuntu package pkg_resources separately:

HACL zooko-desktop:/sdb/zooko/ecometry2rabbit/ecometry2rabbit$ dpkg --search
pkg_resources.py
python-pkg-resources: /usr/share/pyshared/pkg_resources.py
python-pkg-resources: /usr/lib/python2.5/site-packages/pkg_resources.py
python-pkg-resources: /usr/lib/python2.6/dist-packages/pkg_resources.py
HACL zooko-desktop:/sdb/zooko/ecometry2rabbit/ecometry2rabbit$ dpkg --list
python-pkg-resources
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                                  Version              
                                Description
+++-=====================================================-=====================================================-==========================================================================================================================
ii  python-pkg-resources                                  0.6c9-0ubuntu5       
                                Package Discovery and Resource Access using
pkg_resources
HACL zooko-desktop:/sdb/zooko/ecometry2rabbit/ecometry2rabbit$ dpkg --list
python-setuptools
Desired=Unknown/Install/Remove/Purge/Hold
| Status=Not/Inst/Cfg-files/Unpacked/Failed-cfg/Half-inst/trig-aWait/Trig-pend
|/ Err?=(none)/Reinst-required (Status,Err: uppercase=bad)
||/ Name                                                  Version              
                                Description
+++-=====================================================-=====================================================-==========================================================================================================================
un  python-setuptools                                     <none>               
                                (no description available)

The following patch makes ez_setup.py treat this as a case where it needs to
bootstrap setuptools itself:

diff --git a/ez_setup.py b/ez_setup.py
index 6dd60f9..8b2ad2a 100644
--- a/ez_setup.py
+++ b/ez_setup.py
@@ -86,6 +86,11 @@ def setuptools_is_new_enough(required_version):
         else:
             try:
                 pkg_resources.require('setuptools >= %s' % (required_version,))
+            except pkg_resources.DistributionNotFound:
+                # No setuptools installed (even though pkg_resources is
installed)...
+                pkg_resources.__dict__.clear() # "If you want to be absolutely
sure... before deleting it." --said PJE on IRC
+                del sys.modules['pkg_resources']
+                return False
             except pkg_resources.VersionConflict:
                 # An insufficiently new version is installed.
                 pkg_resources.__dict__.clear() # "If you want to be absolutely
sure... before deleting it." --said PJE on IRC

----------
messages: 462
nosy: zooko
priority: bug
status: unread
title: [PATCH] ez_setup.py fails when pkg_resources is installed but setuptools is not

_______________________________________________
Setuptools tracker <setuptools at bugs.python.org>
<http://bugs.python.org/setuptools/issue95>
_______________________________________________


More information about the Distutils-SIG mailing list