当我尝试在另一个目录中导入另一个python类时出现此错误。
这是我的文件夹结构的样子:
main
/prerequisites
- __init__.py
- BitesizeClusterInfo.py
- ComponentStatus.py
__init__.py
BitesizeDecorator.py
BitesizeImp.py
BitesizeInterface.py
constants.py
execute.py
main.py
我正在尝试从BitesizeDecorator.py
导入BitesizeClusterInfo.py
,但出现此错误:
回溯(最近通话最近): 在第1行的文件“ ComponentStatus.py”中 从BitesizeDecorator导入BitesizeDecorator ImportError:没有名为BitesizeDecorator的模块
这是我BitesizeClusterInfo.py
的代码段的样子:
import os
from BitesizeDecorator import BitesizeDecorator
from execute import Execute
class BitesizeClusterInfo(BitesizeDecorator):
def __init__(self, bitesize):
super(BitesizeClusterInfo, self).__init__(bitesize)
def test(self):
super(BitesizeClusterInfo, self).test()
# add command below
print("\n[1] - Checking cluster info...\n")
# grep the output for ease of reading
cmd = "kubectl cluster-info | grep -E 'master|DNS'"
print(Execute.check_if_exists(cmd))
有人可以帮我解决这个问题吗?
答案 0 :(得分:0)
它将是:
from main.BitesizeDecorator import BitesizeDecorator
答案 1 :(得分:0)
您可以将文件BitesizeClusterInfo.py
的位置更改为主文件夹,以使您的工作更加顺畅。
或使用
from main.BitesizeDecorator import BitesizeDecorator
,如果您的主文件夹是项目源:
from main.BitesizeDecorator import BitesizeDecorator