【发布时间】:2020-12-06 21:43:12
【问题描述】:
我正在使用 Python 3.8。我有一个这样的目录结构:
├── package
│ ├── __init__.py
│ └── test2.py
└── test.py
test2的内容:
def x():
print(999)
__init__.py 的内容:
from test2 import *
test.py 的内容:
import package
package.x()
运行 test.py 出现以下错误:
from test2 import *
ModuleNotFoundError: No module named 'test2'
我希望 test.py 按预期工作。请帮忙。
【问题讨论】:
-
我觉得应该是
from .test2 -
导入 test 2 也许试试这个:import package.test2
-
@hjpotter92 谢谢。它解决了问题
标签: python python-3.x python-3.6 python-3.7