【发布时间】:2021-05-21 11:50:26
【问题描述】:
有如下结构:
project/
I-----main.py
I-----src/
I----__init__.py (empty)
I----util.py
I----shared/
I----__init__.py (empty)
I----hello.py
#main.py
from src import util
#util.py (runs without errors)
from shared import hello
#hello.py (runs without errors)
def hello():
print("Hello")
我尝试运行 main.py,得到结果
ModuleNotFoundError: 没有名为“共享”的模块
如何修复 main.py 中的导入?
【问题讨论】:
-
为什么有两个
__init__.pys?请查看stackoverflow.com/questions/2164258/… -
@newQOpenGLWidget 每个包一个
__init__.py,这对我来说是正确的。__init__.py不是构造函数。
标签: python python-3.x python-import