Re: [Modeling-users] Problem in module location
Status: Abandoned
Brought to you by:
sbigaret
From: Sebastien B. <sbi...@us...> - 2003-11-22 19:57:52
|
Hi, <luk...@po...> wrote: > Hi >=20 > 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=3DEC.fetch('Matki') > with > matki=3DEC.fetch('Matki', rawRows=3D1) > all is ok again. The package "BazaAdresowa" isn't in directory where is t= his > 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? >=20 > #------ > from mx.DateTime import * > from Modeling.EditingContext import EditingContext > from GifExtensions.BazaAdresowa.Matki import Matki >=20 > def PokazMatki(): > EC=3DEditingContext() > matki=3DEC.fetch('Matki') > #------ This happens because the framework is not able to find the class: I'm quite sure that your model have packageName=3D"BazaAdresowa", with entity's moduleName=3DMatki and className=3DMatki (whatever that means ;) When you fetch, the framework tries to do the equivalent of: "from <packageName>.<moduleName> import <className>",=20 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. That's why the framework says: > 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 exampl= e, > 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 >=20 > Original exception was: ImportError: No module named BazaAdresowa Back on your other question: > Interesting thing is that when I replace > matki=3DEC.fetch('Matki') > with > matki=3DEC.fetch('Matki', rawRows=3D1) > 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=E9bastien. |