Python package Cython module

Viewed 1738

I have the following package structure:

+ repo/
+ setup.py
+ package/
    + module1/
        + submodule1.py
        + submodule2.pyx
    + module2/
        + submodule3.py

I would like to use submodule2.pyx from submodule1.py by something like:

import submodule2

but I have absolutely no idea how to do this. I tried adding the following lines to my setup.py:

from distutils.core import setup
from setuptools import setup
from Cython.Distutils import build_ext

ext_modules = cythonize(Extension(
        "zindex",
        sources=["ndmg/graph/zindex.pyx"],
        language="c",
))
for e in ext_modules:
    e.pyrex_directives = {"boundscheck": False}

setup(
    name='ndmg',
    ext_modules = ext_modules,
    packages=[
        'package',
        'package.module1',
    ....
)

but was unsuccessful. All of the tutorials I could find had very very simplified examples, so I am not sure how to include Cython modules in my python package when the rest of the package is all just normal python code. Does anybody have any good examples I could follow, or can somebody tell me what I'm doing wrong?

Thanks in advance!

1 Answers
Related