簡體   English   中英

python,Windows 7:ImportError:無法導入名稱X

[英]python, windows 7: ImportError: cannot import name X

我正在使用兩個文件: construct\\core.pyUSBtransport.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.htmlRange在2.9被刪除,所以你可能要安裝2.8.x.

范圍已刪除,GreedyRange不支持[:]語法

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM