[Import-sig] Imputil

Thomas Heller thomas.heller@ion-tof.com
Wed, 31 Jan 2001 15:52:42 +0100


"M.-A. Lemburg" <mal@lemburg.com> wrote:
> Thomas Heller wrote:
> > 
> > I have the impression that we cannot currently
> > import cPickle (for example) by imputil:
> > 
> > cPickle uses PyImport_ImportModule(name) instead of
> > PyImport_Import(name) which would then in turn use the
> > import hook function.
> > cPickle imports copy_reg, string, types.
> > 
> > Is this observation correct?
> 
> >From looking at the cPickle.c code: no. cPickle comes with its
> own PyImport_Import() API which looks very similar to the
> one in Python/import.c (probably there for historic reasons).
> The cPickle implementation uses __import__ as well, so there
> should be no problem.
> 
> The various uses of PyImport_ImportModule() in cPickle are only
> used for standard modules -- I don't think these pose much of
> a problem w/r to imputil and other import hooks, since these
> are either available using the standard import mechanism or
> as frozen modules compiled into the core.

No, these are exactly the problem (maybe only my problem?).
If the standard import mechanism is NOT available (think of
Gordon's installer or my py2exe project) because everything is loaded
from an archive, importing cPickle will fail if you do:

import cPickle
import copy_reg, string, types

but succeed if you do:

import copy_reg, string, types
import cPickle

because in the latter case copy_reg, string, types are
already in sys.modules when 'import cPickle' is executed.

Thomas