【发布时间】:2021-06-12 08:07:01
【问题描述】:
我可以运行 test_pkg1.py 和 test_pkg2.py 但是当我运行 test.py test_pkg1.py 发生错误
发生异常:ImportError 无法从“工具”(未知位置)导入名称“a”
root
├─ pkg1
│ ├─ tools
│ │ ├─ __init__.py
│ │ └─ a.py
│ ├─ __init__.py.py
│ └─ test_pkg1.py
├─ pkg2
│ ├─ tools
│ │ ├─ __init__.py
│ │ └─ b.py
│ ├─ __init__.py.py
│ └─ test_pkg2.py
├─ test.py
└─ d.py
test_pkg1.py
from tools import a
test_pkg2.py
from tools import b
test.py
from pkg2 import test_pkg2
from pkg1 import test_pkg1
【问题讨论】:
-
这可能是因为您在
test.py所在的目录下没有__init__.py文件
标签: python python-3.x import