I am new to Cython extension types and am puzzled by the following related Cython ValueError that is raised at runtime:
ValueError: vrptwms.node.Node has the wrong size, try recompiling
The Node class is defined in the node.pxd and node.pyx files in the vrptwms directory. First content
cdef class Node: """ docstring """ cdef public float x, y, demand cdef public float earliest_start, latest_start, servicetime cdef public int id
and the second - (I temporarily deleted all type declarations, hoping to find the problem)
cdef class Node: """ Represents either a customer or the depot. """
The Node class is then included by the third problemreader.pyx file as follows:
from vrptwms.node cimport Node from vrptwms.node import Node
Compilation works without problems. setup.py contains
from distutils.core import setup from distutils.extension import Extension from Cython.Distutils import build_ext ext_modules = [Extension("route", ["fastroute.pyx"]), Extension("node", ["node.pyx", "node.pxd"]), Extension("problemreader", ["problemreader.pyx"]), ] setup( cmdclass = {'build_ext': build_ext}, ext_modules = ext_modules, )
I also tried adding node.pxd to the problem extension. This problem occurs when the next generated C code
__pyx_ptype_7vrptwms_4node_Node = __Pyx_ImportType("vrptwms.node", "Node", sizeof(struct __pyx_obj_7vrptwms_4node_Node), 1); if (unlikely(!__pyx_ptype_7vrptwms_4node_Node)) {__pyx_filename = __pyx_f[2]; __pyx_lineno = 9; __pyx_clineno = __LINE__; goto __pyx_L1_error;}
and causes
Traceback (most recent call last): File "./cli.py", line 16, in <module> from vrptwms.problemreader import ProblemReader File "node.pxd", line 9, in init problemreader (problemreader.c:4991) cdef class Node: ValueError: vrptwms.node.Node has the wrong size, try recompiling
I deleted all the created .c, .so and .o files several times, but could not get rid of the problem. Any hints (including any documentation links that I might have missed) are welcome.
Edit: The problem does not reproduce if I use relative import of the old style (for example, import Node instead of vrptwms.node) and delete the init .py file, so there is nothing wrong with the source itself. I created a tiny test file that reproduces the problem: c_test.tar.gz (you need to extract it to the directory on PYTHONPATH) and an almost identical case without using a package that does not reproduce it: c_test_w.tar.gz .