With setuptools, “optional” C extension module error is fatal

会有一股神秘感。 提交于 2021-02-09 06:58:07

问题


I'm putting a little time into getting my treap module (like a dict, but always sorted by key) working with setuptools 39.0.1.

I want it to be able to compile and install the Cython version from an included .c file, or to fall back on a pure python version if that fails.

I'm currently using:

setup(
    name='treap',
    py_modules=[
        'treap',
        'py_treap',
        'nest',
        ],
    # ext_modules=cythonize("pyx_treap.pyx"),
    ext_modules=[Extension('pyx_treap', ['pyx_treap.c'], optional=True)],
    # setup_requires=[
    #     'Cython'
    # ],
    version=version,
    description='Python implementation of treaps,
)

...plus a few more options to setup that don't seem relevant.

If I run python3.6 setup.py build, I get:

running build
running build_py
creating build
creating build/lib.linux-x86_64-3.6
copying treap.py -> build/lib.linux-x86_64-3.6
copying py_treap.py -> build/lib.linux-x86_64-3.6
copying nest.py -> build/lib.linux-x86_64-3.6
running build_ext
building 'pyx_treap' extension
creating build/temp.linux-x86_64-3.6
x86_64-linux-gnu-gcc -pthread -DNDEBUG -g -fwrapv -O2 -Wall -g
-fstack-protector-strong -Wformat -Werror=format-security -Wdate-time
-D_FORTIFY_SOURCE=2 -fPIC -I/usr/include/python3.6m -c pyx_treap.c -o
build/temp.linux-x86_64-3.6/pyx_treap.o
pyx_treap.c:4:10: fatal error: Python.h: No such file or directory
 #include "Python.h"
          ^~~~~~~~~~
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

So it seems like despite using Extension('pyx_treap', ['pyx_treap.c'], optional=True), the cython version is not optional.

Am I missing something? Why doesn't it just continue with the pure python modules?

I realize I could install python3.6-dev or similar to eliminate the error, but I don't want to assume the user knows that.

Thanks!

来源:https://stackoverflow.com/questions/59522262/with-setuptools-optional-c-extension-module-error-is-fatal

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!