[英]python, windows 7: ImportError: cannot import name X
我正在使用兩個文件: construct\\core.py
和USBtransport.py
。 以下是兩個文件中的相關代碼:
構建\\ core.py:
class Range(Subconstruct):
__slots__ = ["min", "max"]
def __init__(self, min, max, subcon):
super(Range, self).__init__(subcon)
self.min = min
self.max = max
....
其中Subconstruct是Construct的子類,它們都在代碼的前面定義。
USBtransport.py:
from construct import Subconstruct
from construct import (
Bytes, Container, Embedded, Enum, ExprAdapter, Int16ul, Int32ul, Pass,
Struct, Range,
)
嘗試運行USBtransport.py時遇到此錯誤:
ImportError: cannot import name 'Range'
我看過有關此錯誤的類似文章,它們似乎都源於循環導入。 但是我不認為這是問題所在,因為core.py
從未從USBtransport.py
調用任何類。 我也可以從core.py
導入其他Subconstruct
對象,而不會出現問題。
我也認為錯誤不是源於Range(Subconstruct)
類中的代碼,因為當我注釋掉所有內部代碼並嘗試導入空類時遇到相同的錯誤。
有任何想法嗎?
您確定使用的是正確版本的Construct嗎?
據https://construct.readthedocs.io/en/latest/transition29.html , Range
在2.9被刪除,所以你可能要安裝2.8.x.
范圍已刪除,GreedyRange不支持[:]語法
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.