我有个问题.我想分发我的cython驱动的软件包,但我认为在setup.py中构建它们没有简单的方法.我想setup.py:
目前在我的发痒包中,我正在使用这个非常复杂的代码:
import os
from glob import glob
from distutils.command.build_ext import build_ext as _build_ext
from distutils.command.sdist import sdist as _sdist
from distutils.core import setup
from distutils.core import Extension
def generate_extensions():
return [
# Compile cython-generated .c files into importable .so libraries.
Extension(os.path.splitext(name)[0], [name])
for name in C_FILES
]
# In distribution version, there are no pyx files, when you clone package from git, there will be no c files.
CYTHON_FILES = glob('itchy/*.pyx')
C_FILES = glob('itchy/*.c')
extensions …Run Code Online (Sandbox Code Playgroud) 我对在 Python 和 Cython 代码之间传递数据很感兴趣,以便可以从 C 访问数据而无需 GIL。我正在考虑使用数据类(自 py3.7 起)、命名元组(自 py3.6 起具有很好的定义语法)或 Cython 的扩展类型(cdef classess)来实现这一点。
不幸的是,数据类和命名元组似乎像来自 Cython 的通用对象一样被处理,而没有任何编译成 C 的支持。
可以使用 Cython 扩展类型(cdef 类),但与数据类相比,它们有许多缺点,最重要的是,您必须__init__使用样板代码来实现以设置所有类属性,对吗?