[Python] Collapse multiple submodules to one Cython extension

Discussão em 'Python' iniciado por Stack, Fevereiro 7, 2025.

  1. Stack

    Stack Membro Participativo

    This setup.py:

    from distutils.core import setup
    from distutils.extension import Extension
    from Cython.Build import cythonize

    extensions = (
    Extension('myext', ['myext/__init__.py',
    'myext/algorithms/__init__.py',
    'myext/algorithms/dumb.py',
    'myext/algorithms/combine.py'])
    )
    setup(
    name='myext',
    ext_modules=cythonize(extensions)
    )


    Doesn't have the intended effect. I want it to produce a single myext.so, which it does; but when I invoke it via

    python -m myext.so


    I get:

    ValueError: Attempted relative import in non-package


    due to the fact that myext attempts to refer to .algorithms.

    Any idea how to get this working?

    Continue reading...

Compartilhe esta Página