python - ImportError:没有命名的模块在蟒蛇 2.7
问题描述
当我尝试在不同目录中导入另一个 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
但出现此错误:
Traceback(最近一次调用最后一次):文件“ComponentStatus.py”,第 1 行,从 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))
有人可以帮我解决这个问题吗?
解决方案
这将是:
from main.BitesizeDecorator import BitesizeDecorator
推荐阅读
- php - 为多选 SQL 中的某些值返回 NULL
- node.js - 使用“Access-Control-Allow-Origin”,“*”将socketio与express连接的解决方案是什么
- excel - 将按钮的位置传递给调用子
- google-colaboratory - 上传的文件更改名称
- c# - 尝试在更改场景前等待 15 秒
- nativescript - 如何将 img 的 src 设置为来自 url 的 img。NativeScript
- android - 如何在列表下方放置一个按钮,但如果列表太长,则限制列表的高度
- android - java.lang.IndexOutOfBoundsException 异常
- phabricator - 如何更改 Phabricator 中的默认本地存储库路径?
- sql - 如何按在 SQL Server 中输入的顺序排序?