Building cython extension on windows

51 views
Skip to first unread message

jan pulmann

unread,
Aug 30, 2012, 12:53:27 PM8/30/12
to cython...@googlegroups.com
Hi, I am trying to compile cython bindings to lib2geom [1] on windows. I use thewext's [2] example, slightly modified to work on linux - cmake was used in lib2geom prior to creating bindings, which is a reason I stuck with it.

After bit more cmake tweaking, I got extension types to build, but loading them result in following  error code

>>> import cy2geom
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "cy2geom.pyx", line 5, in init cy2geom (C:\src\lib2geom\src\2geom\cythonbindings\cy2geom.cxx:671)
    from _cy_primitives import cy_Angle as Angle
  File "_cy_rectangle.pxd", line 169, in init _cy_primitives (C:\src\lib2geom\src\2geom\cythonbindings\_cy_primitives.cxx:15404)
    cdef class cy_Interval:
  File "_cy_primitives.pxd", line 42, in init _cy_rectangle (C:\src\lib2geom\src\2geom\cythonbindings\_cy_rectangle.cxx:37231)
    cdef class cy_Angle:
ImportError: No module named _cy_primitives


This circular importing is due to multiple modules prefixed _cy_ in which code is organized - extension types from these modules are imported in cy2geom.pyx file.

Basically, _cy_primitives.pyx imports some declarations from _cy_rectangle.pxd, and _cy_rectangle.pxd import some declarations form _cy_primitives.pxd. This works fine on linux (archlinux and ubuntu tested so far), but on Windows (7 in my case) python seems to lose track of files and is unable to locate _cy_primitives after few bumps in importing.

Lines mentioned in .cxx files are:

cy2geom.cxx:671
  __pyx_t_2 = __Pyx_Import(((PyObject *)__pyx_n_s___cy_primitives), ((PyObject *)__pyx_t_1), -1); if (unlikely(!__pyx_t_2)) {__pyx_filename = __pyx_f[0]; __pyx_lineno = 5; __pyx_clineno = __LINE__; goto __pyx_L1_error;}


_cy_primitives.cxx:15404
  __pyx_ptype_14cythonbindings_13_cy_rectangle_cy_Interval = __Pyx_ImportType("_cy_rectangle", "cy_Interval", sizeof(struct __pyx_obj_14cythonbindings_13_cy_rectangle_cy_Interval), 1); if (unlikely(!__pyx_ptype_14cythonbindings_13_cy_rectangle_cy_Interval)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 169; __pyx_clineno = __LINE__; goto __pyx_L1_error;}


_cy_rectangle.cxx:37231
  __pyx_ptype_14cythonbindings_14_cy_primitives_cy_Angle = __Pyx_ImportType("_cy_primitives", "cy_Angle", sizeof(struct __pyx_obj_14cythonbindings_14_cy_primitives_cy_Angle), 1); if (unlikely(!__pyx_ptype_14cythonbindings_14_cy_primitives_cy_Angle)) {__pyx_filename = __pyx_f[1]; __pyx_lineno = 42; __pyx_clineno = __LINE__; goto __pyx_L1_error;}


I think I've isolated my problem to this, because one of the modules (_common_decl) is completely stand-alone, and importing it alone works without errors.

So far I tried to rewrite module hierarchy to use it as

>>> import cythonbindings

using __init__.py file, but the error message did not change. Does anyone have any pointers I should look at, or idea what might have gone wrong on windows?
Thanks in advance :)
Best regards
Jan Pulmann

[1]: http://bazaar.launchpad.net/~lib2geom-hackers/lib2geom/trunk/files/head:/src/2geom/cython-bindings/
[2]: https://github.com/thewtex/cython-cmake-example

jan pulmann

unread,
Aug 31, 2012, 10:07:24 AM8/31/12
to cython...@googlegroups.com, jan pulman
Hi, I am sorry, it looks problem lies elsewhere. I used python2 on linux and python3 on windows (I don't know why I haven't mentioned this).

Using python3 on linux leads to same problems, importing doesn't stop and continues only to fail with non-related error message.
https://gist.github.com/3552432
is output of
#python -v -v -c "import cy2geom"

Why does this error occur only with python3? Generated code looks the same.

Is there any way to get rid of this without removing circular imports? Right now, I use scheme similar to following:

_cy_primitives.pxd declares extension type cy_Point
_cy_primitives.pyx implements methods for cy_Point

_cy_rectangle.pxd declares extension type cy_Rectangle
_cy_rectangle.pyx implements methods for cy_Rectangle

imports:

_cy_rectangle.pxd cimports cy_Point from _cy_primitives
_cy_primitives.pyx cimports cy_Rectangle from cy_rectangle

--------------------
I used to think that it's okay, since cimporting only looks at .pxd parts of declarations, but since pxd and pyx are merged, this isn't necessarily true.

I might follow-up with question about dealing with interwinted C++ modules in cython :)

Best regards
Jan Pulmann
Reply all
Reply to author
Forward
0 new messages