看起来我在 python 导入方面度过了非常艰难的一天。我正在使用 Flask 并尝试组织我的应用程序结构。我在 GAE 上使用它,因此必须将 python 包放入我的应用程序本身。它看起来像下面这样:-
-MyFolder
-flask
-werkzeug
-Myapp
- __init__.py
-templates
-static
-views.py
-blinker
截至目前,我将 blinker 库导入到 Myapp 的 __init__ 中。但我想将这些额外的包(如 blinker)组织到一个辅助包中,以便看起来像这样。
-helper
-__init__.py
-blinker
(blinker 的 __init__.py 文件是这样的)
from blinker.base import.....
但是当我尝试使用
将 blinker 导入 Myapp 的 __init__ 时from helper import blinker
我收到一个导入错误,提示没有名为 blinker.base 的模块。为什么会发生这种情况。看起来它正在寻找当前包之外的信号灯包。为什么会发生?
最佳答案
sys.path.append
也可以满足您的目的。
关于python - 我的另一个 python 导入问题,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/3980717/