[英]ImportError: No module named <modulename> in python 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
我正在嘗試從BitesizeClusterInfo.py
導入BitesizeDecorator.py
,但出現此錯誤:
回溯(最近一次調用):文件“ComponentStatus.py”,第 1 行,來自 BitesizeDecorator import BitesizeDecorator ImportError: No module named 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
您可以將文件BitesizeClusterInfo.py
的位置更改為主文件夾,以使您的線條工作。
或使用
from main.BitesizeDecorator import BitesizeDecorator
如果您的主文件夾是項目源:
from main.BitesizeDecorator import BitesizeDecorator
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.