python添加模块引用,在python中的同级子包之间导入模块(包内引用)

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

我还有问题。在

那么我在这里遗漏了什么?我认为绝对进口是处理子包的方法。在

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值