具有如下项目结构:
myproject/
|--- __init__.py
|--- application.py
|--- modules/
|--- __init__.py
|--- parser.py
|--- utils/
|-- __init__.py
|-- helpers.py
在utils/helpers.py
中:
def find_stuff():
return stuff
def help_me():
return some_help
在modules/parser.py
中,我要导入find_stuff
(仅此)。
我尝试了以下操作:
from ..utils.helpers import find_stuff
但是...
ImportError: cannot import name 'find_stuff' from 'myproject.utils.helpers' (/Users/myself/myproject/utils/helpers.py)
在这里应该做什么?
注意:
from ..utils import helpers
然后在helpers.find_stuff
中使用parser.py
-我认为Python的导入系统已被深思熟虑,因此我们可以准确地避免这种情况< / li>
答案 0 :(得分:3)
在utils
下,您没有__init__.py
文件。我认为您将需要一个,即使是空的也可以解决问题。
答案 1 :(得分:2)