python - 使用 Cython 编译多 python 文件并生成一个 so
问题描述
我有一些 python 文件,并且所有操作都在 Main 文件中暴露给其他人。我想编译它们并分发给.so
其他人。
我尝试用 cython 编译它们,但生成了不止一个.so
(有效但不完美)。
例子:
文件夹结构为:
CythonExample/
|——for_call.py
|——setup.py
|——Student.py
安装程序.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_ext --inplace
然后我得到Student.so
和for_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_ext --inplace
,好吧,只sayname.so
生成。但是当我尝试导入它时。
import sayname
ImportError: dynamic module does not define init function (initsayname)
谢谢。
解决方案
推荐阅读
- mongodb - Scala MongoDB 驱动程序的磁铁模式
- javascript - 更新依赖项后,如何让 Visual Studio Code IDE 更新类型?
- twilio - Twilio 无法记录来电对话(与留言无关)
- python - 在 jupyter notebook 中使用变量名运行 py 文件
- r - 在R中另一个数据帧的特定位置添加一个数据帧的行
- javascript - 无法一次在三个地方读取 null 的属性“样式”
- ios - 使用 showBluetoothAccessoryPicker 会导致 SceneDelegate 出现错误
- python - 计算数组中介于 0 和 1 之间的所有值
- ios - 正在调用 CollectionView `DidSelect` 方法但没有推送下一个 VC,如何解决?
- artifactory - 由于分割违规导致的人工崩溃