【发布时间】:2019-06-14 09:27:29
【问题描述】:
我的目录结构:
test.py
module/
importer.py
importee.py
__init__.py
所以在我的目录中,我有 test.py,然后是另一个已初始化为模块的目录。在该模块中,有一个 importer.py 文件,它导入了一个 importee.py 文件。为了测试导入是否有效,我在 importee.py 中做了一个简单的函数,并尝试在 importer.py 中使用它(即我直接运行 importer.py);它工作得很好。
但是当我进入 test.py 并有 import 语句 from module import * 并尝试运行它(没有任何其他代码)时,它给出了一个错误,可以追溯到 importer.py 中的 import 语句,说 @987654327 @
如果重要,module 目录中的__init__.py 具有正确指定的__all__ 函数。
我认为这不是重复的,尽管有类似标题的帖子,例如 this 或 this 或 this 或 this;我一直在寻找几个小时,但仍然不知道是什么原因造成的。
有什么想法吗?非常感谢任何帮助。
编辑:四个文件的内容:
init.py
__ all __ = ["importee", "importer"]
importee.py
def example():
print("hey")
importer.py
from importee import *
example()
test.py
from module import *
当我运行 importer.py 时,我没有收到任何错误,但是当我运行 test.py 时,我收到一个错误,该错误可以追溯到 importer.py 的第一行,说 No module named 'importee' found,即使我不明白直接运行importer.py时出错...
【问题讨论】:
-
如果您概述所有四个
.py文件的内容(即使您编写它们的简化版本),这会更清楚 -
@CharlesLandau 抱歉,一开始应该这样做,现在我已经编辑了它们。
标签: python python-3.x import python-module