我有一个库使用 Cython 编写,以提高执行速度,但很多场景安装 gcc 等编译工具很麻烦,所以想同时提供一个纯 Python 的版本,而我又不想类似的代码写两套。
有什么办法能把 .pyx 文件中的静态类型声明等等去掉,变成纯 Python 代码?
|  |      1monsterxx03      2019-11-15 16:12:59 +08:00  1 应该打个 wheel 格式的包, 其他地方安装的时候就不用编译了: https://pythonwheels.com/ | 
|  |      2guyskk0x0 OP @monsterxx03 wheel 包需要在 windows, mac, linux 上分别打包,也是很麻烦 | 
|      3superrichman      2019-11-15 17:17:00 +08:00 via iPhone 也许可以考虑扔到 docker 里去? | 
|  |      4ethego      2019-11-15 17:32:11 +08:00 当然要分别打包,cython 写的玩意是编译到 c 再进一步编译到 binary 的,没有可以编译到 python 的方法。如果要分发二进制,就需要按系统分别打包。 | 
|  |      5ethego      2019-11-15 17:32:47 +08:00 不可以,你可以在手写一个纯 python 的版本。 | 
|  |      6wangyzj      2019-11-15 18:05:00 +08:00 pyinstaller | 
|      7hakono      2019-11-15 18:29:36 +08:00 via iPhone  1 别瞎想,照着你的 c 代码再写个 python 实现更快 | 
|  |      8guyskk0x0 OP @ethego #4  @hakono #7 我暂时用正则和字符串替换实现了 .pyx 转 .py ,实现很不优雅,靠单元测试保证转换后功能正确。 https://github.com/guyskk/validr/pull/30/files#diff-fcbabf283e1a432f9d3830f80cd5bdd3 |