使用Cython编译多python文件并生成一个so

使用Cython编译多python文件并生成一个so,python,cython,Python,Cython,我有一些python文件,所有的操作都暴露在主文件中。我想编译它们并分发一个。所以给其他人 我试着用cython编译它们,但不止一个。因此生成了(可以工作,但并不完美) 例如: 文件夹结构为: CythonExample/ |——for_call.py |——setup.py |——Student.py setup.py from distutils.core import setup, Extension from Cython.Build import cythonize setup(

我有一些python文件,所有的操作都暴露在主文件中。我想编译它们并分发一个
。所以
给其他人

我试着用cython编译它们,但不止一个
。因此生成了
(可以工作,但并不完美)

例如:

文件夹结构为:

CythonExample/
|——for_call.py
|——setup.py
|——Student.py
setup.py

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

setup(
    ext_modules=cythonize(["Student.py", "for_call.py"]),
)
python setup.py build\u ext--in place
然后我得到
Student.so
for\u call.so

我将setup.py修改为:

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

setup(
    name='sayname',
    ext_modules=cythonize(Extension("sayname", sources=["Student.py", "for_call.py"], language="c")),
)
然后
python setup.py build\u ext--in place
,那么,只有
sayname.so
生成。但当我尝试导入它时

import sayname

ImportError: dynamic module does not define init function (initsayname)
谢谢。

也可能有用,但描述的文件夹结构略有不同。但总的结果是Cython并不真正支持这一点,但有时可以用黑客的方式进行,这可能也很有用,但描述了一种稍微不同的文件夹结构。但总的结果是,Cython并不真正支持这一点,但有时可以用黑客的方式来实现