Discussion:
[Modeling-users] Problem in module location
l***@poczta.fm
2003-11-22 16:45:03 UTC
Permalink
Hi

I notice a strange behavior. When I import this script showed below all is
ok, Python finds the module "Matki" (sorry for strange names - ther are in
Polish :-). But when I call function "PokazMatki()" I got this error.
Interesting thing is that when I replace
matki=EC.fetch('Matki')
with
matki=EC.fetch('Matki', rawRows=1)
all is ok again. The package "BazaAdresowa" isn't in directory where is this
script. The package is in Python directory in subdirectory "GifExtensions".
When I copy the package "BazaAdresowa" to the directory where the script is
everything works fine again. Strange isn't it? Could you give me some
explanation?

#------
from mx.DateTime import *
from Modeling.EditingContext import EditingContext
from GifExtensions.BazaAdresowa.Matki import Matki

def PokazMatki():
EC=EditingContext()
matki=EC.fetch('Matki')
#------

Traceback (most recent call last):
File "<stdin>", line 1, in ?
File "PS_Baza.py", line 55, in PobierzMatki
matki=EC.fetch('Matki')
File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\EditingContext.py", line 1419, in
fetch
return self.objectsWithFetchSpecification(fs)
File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\EditingContext.py", line 1302, in
objectsWithFetchSpecification
objects=self.parentObjectStore().objectsWithFetchSpecification(fs, ec)
File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\ObjectStoreCoordinator.py", line
434, in objectsWithFetchSpecification
return store.objectsWithFetchSpecification(aFetchSpecification,
anEditingContext)
File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\DatabaseContext.py", line 1765,
in objectsWithFetchSpecification
object=channel.fetchObject()
File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\DatabaseChannel.py", line 269, in
fetchObject
object=cd.createInstanceWithEditingContext(ec)
File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\EntityClassDescription.py", line
177, in createInstanceWithEditingContext
theClass=self.classForInstances()
File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\EntityClassDescription.py", line
161, in classForInstances
theClass=classForEntity(self._entity)
File "C:\PROGRA~1\Zope2.6.2\bin\Modeling\EntityClassDescription.py", line
521, in classForEntity
raise ImportError, err_msg
ImportError: Unable to locate class BazaAdresowa.Matki.Matki corresponding
to entity 'Matki'.
It is possible that the model's packageName, or the entity's moduleName or
className do not correspond to where the module is installed --for example,
you might have moved it to a sub-package. You can solve this easily by
updating your model so that 'packageName.moduleName.className' points to
the exact location where the class is installed

Original exception was: ImportError: No module named BazaAdresowa


****************************
* Łukasz Łakomy
* ***@poczta.fm
****************************
Sebastien Bigaret
2003-11-22 17:58:03 UTC
Permalink
Hi,
Post by l***@poczta.fm
Hi
I notice a strange behavior. When I import this script showed below all is
ok, Python finds the module "Matki" (sorry for strange names - ther are in
Polish :-). But when I call function "PokazMatki()" I got this error.
Interesting thing is that when I replace
matki=EC.fetch('Matki')
with
matki=EC.fetch('Matki', rawRows=1)
all is ok again. The package "BazaAdresowa" isn't in directory where is this
script. The package is in Python directory in subdirectory "GifExtensions".
When I copy the package "BazaAdresowa" to the directory where the script is
everything works fine again. Strange isn't it? Could you give me some
explanation?
#------
from mx.DateTime import *
from Modeling.EditingContext import EditingContext
from GifExtensions.BazaAdresowa.Matki import Matki
EC=EditingContext()
matki=EC.fetch('Matki')
#------
This happens because the framework is not able to find the class: I'm quite
sure that your model have packageName="BazaAdresowa", with entity's
moduleName=Matki and className=Matki (whatever that means ;)

When you fetch, the framework tries to do the equivalent of:
"from <packageName>.<moduleName> import <className>",
in your case: "from BazaAdresowa.Matki import Matki".

But this does not work, because as your script shows it, package
BazaAdresowa is in GifExtensions, not in the python path. So the
solution is: either add BazaAdresowa in your python path, or change the
model so that its package name is "GifExtensions.BazaAdresowa".

In any case and as a general rule, wherever in the python code the
statement "from <packageName>.<moduleName> import <className>" fails,
the framework will equally fails. This is something that should probably
be put somewhere, I'll try not to forget and add that to the faq.
Post by l***@poczta.fm
ImportError: Unable to locate class BazaAdresowa.Matki.Matki corresponding
to entity 'Matki'.
It is possible that the model's packageName, or the entity's moduleName or
className do not correspond to where the module is installed --for example,
you might have moved it to a sub-package. You can solve this easily by
updating your model so that 'packageName.moduleName.className' points to
the exact location where the class is installed
Original exception was: ImportError: No module named BazaAdresowa
Interesting thing is that when I replace
matki=EC.fetch('Matki')
with
matki=EC.fetch('Matki', rawRows=1)
all is ok again.
fetch w/ rawRows does not try to instanciate any objects, it just
returns a dictionary from the db -> it does not try to import any class
in the process, and that's why it does not fail.

I hope I succedeed to make it clear, if not, you can keep picking on
me ;)

-- Sébastien.

Loading...