How to deal with Cython ValueError

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. """ # pylint: disable-msg=C0103, R0913 def __init__(self, id_, x, y, demand, earliest_start, latest_start, servicetime): """ docstring """ self.x = float(x) self.y = float(y) self.demand = float(demand) self.earliest_start = float(earliest_start) self.latest_start = float(latest_start) self.servicetime = float(servicetime) self.id = int(id_) # some internal functions 

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 .

+4
source share
2 answers

Robert Bradshaw offered some tips on the cython-users mailing list. The bottom line is that manually (recompiling) .pyx files using cython *.pyx and the original script setup works. There is also a newer way to record the installation of the script described in CEP 201 - Distutils preprocessing , which should help, but does not work in my current setup with Cython 0.14.1.

+1
source

I do not understand what you are doing here:

 from vrptwms.node cimport Node from vrptwms.node import Node 

When importing twice with the same name, the second import overrides the first.

0
source

All Articles