[英]python, windows 7: ImportError: cannot import name X
I'm working with two files: construct\\core.py
and USBtransport.py
. 我正在使用两个文件: construct\\core.py
和USBtransport.py
。 Below is the relevant code from both files: 以下是两个文件中的相关代码:
construct\\core.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
....
where Subconstruct is a subclass of Construct which were both defined earlier in the code. 其中Subconstruct是Construct的子类,它们都在代码的前面定义。
USBtransport.py: USBtransport.py:
from construct import Subconstruct
from construct import (
Bytes, Container, Embedded, Enum, ExprAdapter, Int16ul, Int32ul, Pass,
Struct, Range,
)
I run into this error when trying to run USBtransport.py: 尝试运行USBtransport.py时遇到此错误:
ImportError: cannot import name 'Range'
I've looked at similar posts about this error and they seem to all stem from circular importing. 我看过有关此错误的类似文章,它们似乎都源于循环导入。 However I don't think that's the issue here since core.py
never calls any classes from USBtransport.py
. 但是我不认为这是问题所在,因为core.py
从未从USBtransport.py
调用任何类。 I'm also able to import other Subconstruct
objects from core.py
without problems. 我也可以从core.py
导入其他Subconstruct
对象,而不会出现问题。
I also don't think the error stems from the code inside class Range(Subconstruct)
since I get the same error when I comment out all the code inside and just try to import an empty class. 我也认为错误不是源于Range(Subconstruct)
类中的代码,因为当我注释掉所有内部代码并尝试导入空类时遇到相同的错误。
Any ideas? 有任何想法吗?
Are you sure you're using the right version of Construct ? 您确定使用的是正确版本的Construct吗?
According to https://construct.readthedocs.io/en/latest/transition29.html , Range
was removed in 2.9, so you might want to install 2.8.x. 据https://construct.readthedocs.io/en/latest/transition29.html , Range
在2.9被删除,所以你可能要安装2.8.x.
Range removed, GreedyRange does not support [:] syntax 范围已删除,GreedyRange不支持[:]语法
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.