[Distutils] pkg_resources: getting to resources in other packages

Kevin Dangoor dangoor at gmail.com
Mon Jul 11 22:19:41 CEST 2005


I've found a scenario that isn't working, and I figured I'd toss this
out there to see if a change is needed in setuptools or in my
scenario...

Picture something like this:

toppackage
    __init__.py
    somemod.py
    lowerpackage
        __init__.py
        someresource.txt

In somemod.py:
import pkg_resources
s = pkg_resource.resource_string("toppackage.lowerpackage", "someresource.txt")

This will fail with a KeyError in get_provider(moduleName).

If there is an import toppackage.lowerpackage before the
resource_string call, then it works fine.

In this particular instance, I'm going to go ahead and implement logic
to ensure that the package has been imported. But, I was figuring that
it might be nice if pkg_resource handled this...

What say you all?

Kevin


More information about the Distutils-SIG mailing list