alecwh
alecwh

Reputation: 984

Trying to import a module that imports another module, getting ImportError

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?

Upvotes: 0

Views: 587

Answers (2)

Wojciech Bederski
Wojciech Bederski

Reputation: 3922

You either need to

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

Upvotes: 1

brendan
brendan

Reputation: 2743

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.

Upvotes: 2

Related Questions