problem with "ImportError: No module named..." and sockets
daniel.watrous at gmail.com
Wed Oct 1 19:55:51 CEST 2008
On Sep 30, 5:49 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> En Tue, 30 Sep 2008 19:44:51 -0300, Daniel <daniel.watr... at gmail.com>
> > On Sep 30, 4:17 pm, "Gabriel Genellina" <gagsl-... at yahoo.com.ar>
> > wrote:
> >> En Tue, 30 Sep 2008 18:38:19 -0300, Daniel <daniel.watr... at gmail.com>
> >> escribió:
> >> > [BEGIN CODE]
> >> > #!/usr/bin/python
> >> > import SocketServer
> >> > import os, sys
> >> > newpath = os.path.normpath( os.path.join( __file__, "../../.." ))
> >> > sys.path.insert(0, newpath)
> >> > from pop.command.UpdateCommand import *
> >> > import cPickle
> >> > Traceback (most recent call last):
> >> > [...]
> >> > ImportError: No module named UpdateCommand
> >> > I import the module at the top of the file server.py, but it doesn't
> >> > throw the ImportError until it tries to unpickle.
> >> Notice that you don't import the UpdateCommand module - you import all
> >> names defined inside it instead. It's not the same thing.
> >> Seehttp://effbot.org/zone/import-confusion.htm
> >> --
> >> Gabriel Genellina
> > Thank you Gabriel,
> > The class inside that module has the same name, UpdateCommand. Since
> > this is the object that was pickled, it should be available to the
> > unpickle command. I already understood the difference between import
> > methods and I think I'm covered. I did just try "import
> > pop.command.TesterUpdateCommand" instead and I get the same error.
> (TesterUpdateCommand != UpdateCommand...)
> In your *pickling* code, just before pickling the object, see what you get
> from this:
> cls = obj.__class__
> print cls.__module__
> print cls.__name__
> Suppose you get "SomeModuleName" and "SomeClassName". Then, in your
> *unpickling* environment, this must succeed:
> import SomeModuleName
> cls = SomeModuleName.SomeClassName
> If not, you should rearrange things (on both sides, probably) to make the
> reference work. This is basically what pickle does.
> Looks like the module lives in a package - make sure you import the
> *package* both when pickling and unpickling. The sys.path manipulation
> looks suspicious.
> Gabriel Genellina
This turned out to be a problem with PyScripter. When I open the same
files in Komodo they work fine.
Sorry for the trouble.
More information about the Python-list