views:

214

answers:

2

In ajax.py, I have this import statement:

import components.db_init as db

In components/db_init.py, I have this import statement:

# import locals from ORM (Storm)
from storm.locals import *

And in components/storm/locals.py, it has this:

from storm.properties import Bool, Int, Float, RawStr, Chars, Unicode, Pickle
from storm.properties import List, Decimal, DateTime, Date, Time, Enum
from storm.properties import TimeDelta
from storm.references import Reference, ReferenceSet, Proxy
from storm.database import create_database
from storm.exceptions import StormError
from storm.store import Store, AutoReload
from storm.expr import Select, Insert, Update, Delete, Join, SQL
from storm.expr import Like, In, Asc, Desc, And, Or, Min, Max, Count, Not
from storm.info import ClassAlias
from storm.base import Storm

So, when I run that import statement in ajax.py, I get this error:

<type 'exceptions.ImportError'>: No module named storm.properties

I can run components/db_init.py fine without any exceptions... so I have no idea what's up.

Can someone shed some light on this problem?

+2  A: 

I would guess that storm.locals' idea of its package name is different from what you think it is (most likely it thinks it's in components.storm.locals). You can check this by printing __name__ at the top of storm.locals, I believe. If you use imports which aren't relative to the current package, the package names have to match.

Using a relative import would probably work here. Since locals and properties are in the same package, inside storm.locals you should be able to just do

from properties import Bool

and so on.

brendan
This does solve my problem, but it unearths another. All of Storm's internal modules use 'import storm.{module_name}' for some reason. I think this means that Storm cannot be used by Grandparent modules!
alecwh
I spoke too soon. Wuub has listed some methods for circumnavigating this issue below.
alecwh
+1  A: 

You either need to

  • add (...)/components/storm to PYTHONPATH,
  • use relative imports in components/storm/locals.py or
  • import properties instead of storm.properties
wuub