可能重复:
How to import the src from the tests module in python如何导入模块
我想打电话给其位于另一个目录另一个模块。我的代码结构是
flask_beginner/
app.py
models/
__init__.py
user.py
tests/
__init__.py
user_test.py
我想从user_test.py调用用户模块。我user_test.py是这样的..
import models.user
....
但它引发错误,任何模块名为models.user
你有什么想法? 我的Python版本是2.7.2。(带有virtualenv)
在此先感谢。
感谢我的理解(其中,当然,你应该用正确的路径,其中,在这种情况下,将
'../models/user.py'
更换<the_path_to_the_module>
)。我从我的根目录运行模块,它成功了!谢谢。 – nobinobiru