[Distutils] zip imports ftw

Chris McDonough chrism at plope.com
Sun Sep 16 19:23:43 CEST 2012


On Sun, 2012-09-16 at 08:07 -0400, Daniel Holth wrote:
> Of course the major potentially non obvious caveats are that a lot of python code doesn't use the API to load data from the importer path, instead using __file__ and assuming everything is one, and that sometimes (shared libraries) the system can't load it unless its a real file.

This is easy to work around in brand new code using pkg_resources, so
it's generally only a problem with older code, or code which can depend
only on the stdlib.  Unfortunately, the stdlib doesn't have much to help
here.  There's pkgutil.get_data but it doesn't really work well if you
need to get a filelike handle to a resource, or you need to list the
contents of a directory, and other things which pkg_resources does very
nicely, so it seems like Python isn't really serious about allowing code
in zipfiles to be a viable alternative to file-and-directory-based code.

- C




More information about the Distutils-SIG mailing list