在ajax.py中,我有这个import语句:
import components.db_init as db
在components / db_init.py中,我有这个import语句:
# import locals from ORM (Storm)
from storm.locals import *
在components / storm / locals.py中,它有:
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
所以,当我在ajax.py中运行import语句时,我收到此错误:
<type 'exceptions.ImportError'>: No module named storm.properties
我可以运行components / db_init.py,没有任何例外......所以我不知道是什么。
有人可以解释这个问题吗?
答案 0 :(得分:2)
我猜想storm.locals
'它的包名称的概念与你的想法不同(很可能它认为它在components.storm.locals
中)。我相信,您可以在__name__
顶部打印storm.locals
来查看此内容。如果使用与当前包不相关的导入,则包名必须匹配。
使用相对导入可能在这里工作。由于locals
和properties
位于同一个包中,因此您应该可以storm.locals
内的
from properties import Bool
等等。
答案 1 :(得分:1)
您需要