我虽然很容易,但我无法做到。 我在the doc中读到这应该有效:
a/__init__.py
#nothing here
a/b.py
var = "hello world"
a/c.py
import b
print(b.var)
来自.
:
>>> import a.c
ImportError: No module named 'b'
但它没有......我忘记了什么?是因为我使用Python 3吗?
答案 0 :(得分:1)
是的,这是因为Python3。
In Python 3, implicit relative imports within packages are no longer available
答案 1 :(得分:0)
没关系,我相信你应该把你的文件保存在Program Files(x86)/ Lib中来创建一个新模块,就像Python 2.7.6一样,但它很可能也适用于Python 3.0。