对于setuptools,“可选”C扩展模块错误

2024-06-08 08:50:21 发布

您现在位置:Python中文网/ 问答频道 /正文

我花了一点时间来获取我的treap模块(比如dict,但是 总是按键排序)使用distutils。你知道吗

我希望它能够编译和安装Cython版本从一个 included.c文件,或者在失败时使用纯python版本。你知道吗

我目前正在使用:

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,
)

…再加上一些不相关的设置选项。你知道吗

如果我运行python3.6设置.py建造,我得到:

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

因此,尽管使用了扩展名('pyx\u treap',['pyx\u treap.c'], optional=True),cython版本不是可选的。你知道吗

我错过什么了吗?为什么不继续使用纯python呢 模块?你知道吗

我意识到我可以安装python3.6-dev或类似软件来消除错误, 但我不想假设用户知道这一点。你知道吗

谢谢!你知道吗


Tags: 模块pybuild版本creatingmoduleslinuxlib