When packages are structured into subpackages (as with the sound package in the example), you can use absolute imports to refer to submodules of siblings packages. For example, if the module sound.filters.vocoder needs to use the echo module in the sound.effects package, it can use from sound.effects import echo.
但是,当我在本地计算机上尝试此操作时,如将sound/filters/vocoder.py的内容设置为:
from sound.effects import echo
运行方式如下:
$python vocoder.py
我得到了一个错误:Traceback (most recent call last):
File "vocoder.py", line 1, in
from sound.effects import echo
ImportError: No module named sound.effects
如果我进入sound目录,在iPython shell中尝试以下操作,并尝试导入包,方法如下:
^{pr2}$
或者In [3]: import sound.filters.vocoder
---------------------------------------------------------------------------
ImportError Traceback (most recent call last)
in ()
----> 1 import sound.filters.vocoder
ImportError: No module named sound.filters.vocoder
我还有问题。在
那么我在这里遗漏了什么?我认为绝对进口是处理子包的方法。在