【发布时间】:2018-06-01 16:50:36
【问题描述】:
我有 3 个 cython 文件:
文件 1 - candle.pxd:
cdef class Candle:
cdef:
int ts
文件 2 - candle.pyx:
cdef class Candle:
def __init__(self, int ts):
self.ts = ts
文件 3 - feeder.pyx:
from src.cython.candle cimport Candle
cdef class Feeder:
cdef instantiate_first_candle(self):
cdef int a = 1
# Instantiates Candle
cdef Candle candle = Candle(a)
它抛出的确切错误是:
from src.cython.feeder import Feeder
File "src/cython/candle.pxd", line 3, in init feeder
ValueError: src.cython.candle.Candle has the wrong size, try recompiling. Expected 16, got 24
我不知道发生了什么以及如何解决这个问题。我尝试了很多不同的方法,但都没有成功。
更新:
我能够在 IPython 上导入 Candle,当我尝试实例化一个对象时出现此错误:
AttributeError: 'candle.Candle' object has no attribute 'ts'
【问题讨论】:
-
我在尝试时没有收到此错误。显示您的编译脚本可能是值得的。您还可以查看
import src.cython.candle; print(src.cython.candle.__file__)(在 Python 终端中),以检查您是否以某种方式在 Python 路径上以某种方式结束了额外的“蜡烛” -
@DavidW,感谢大卫,我能够修复它,因为我在某处读过会导致我的代码崩溃的东西。我只是发布解决方案。
-
@DavidW,我在终端中运行它并得到一个不同的错误:
.Feeder' has no attribute '__reduce_cython__'似乎其他人也有类似的问题:github.com/cython/cython/issues/1953
标签: python compilation cython