我正在开发一个Python包,其中将包含可重用的代码、类等,这些代码和类将导入到我们的其他Python程序中。不过,我真的很难让导入正常工作,要么导入由于init.py中的更改而停止工作,要么我会得到一个导入错误
from .util import configParser, writeToAppLog # currently trying this method...
from .itm import normaliseAgentVersion
# from . import util # would prefer this method so we don't have to define every single thing our module will "export"
# from . import itm
__all__ = ["util", "itm"]
import *
,因为它屏蔽了从…导入函数的位置。from . import itmlcm
itmlcm.normaliseAgentVersion("06.30.07.00")
上面的test.py脚本似乎可以工作,当然是在VS代码中。但是,它会产生以下错误:
Traceback (most recent call last):
File ".\LCM\bin\test.py", line 4, in <module>
from . import itmlcm
ImportError: attempted relative import with no known parent package
我们如何正确地构造它,以便开发包并将其导入到代码中使用
目前没有回答
相关问题 更多 >
编程相关推荐