python - 在 Ubuntu Python 3 上构建的 Cython+distutils 在链接期间更改了模块库名称

标签 python cython distutils

我正在使用 Cython 和 distutils。 我的一个测试中,构建了一个二进制扩展模块。此后,我的其他测试之一将导入 二进制模块并对其进行测试。在 Travis-CI 上,链接器命令会更改名称。请参见下面的屏幕截图:编译器正确构建了 test01.o,但链接器错误地创建了 test01.cpython-34m.so:我想要 test01.so.

enter image description here

以上截图为Python 3.4; Python 2.7 没有出现这个问题,这让我怀疑 Python 特定的 distutils 可能做了不同的事情。

从我的主脚本调用的 distutils setup() 函数没有做任何特别的事情:

setup(
    cmdclass = {'build_ext': build_ext},
    ext_modules = ext_modules,
    include_dirs=[numpy.get_include()]
)

这里 ext_modules 是一系列 Extension() 类,从 distutils.extension 导入。

我已经浏览了 2.7 和 3.4 的 distutils 文档,没有什么不同。什么可能导致名称更改,我可以在 setup()Extension() 实例化中指定哪些选项以防止名称更改?


编辑:我已经设置了一个运行 Ubuntu 13.10 的本地 VM,并且可以确认,如上所述,Python 2.7 生成 test01.so 而 Python 3.4 生成 test01.cpython-34m.so。因此,这个问题与 travis-ci 无关,我正在删除该标签并编辑标题。


编辑: 事实上,这是对 distutils 的更改,made in 3.2 .我仍在想办法让我的导入语句看起来正确。


编辑:天哪,python 文档中的 helloworld 示例在 Ubuntu 13.10 上的 Python 3.4.1 (Anaconda) 上生成了 helloworld.cpython-34m.so。 Python 的 sysconfig 模块以 sysconfig.get_config_var('SO') == 'cpython-34m.so' 启动。

我觉得要咆哮了。

最佳答案

感谢@ncoghlan_dev,谜团解开了。重命名更改是在 PEP 3149 中进行的.事实证明,即使二进制扩展模块的名称可能类似于 helloworld.cpython-34m.so,但当您实际上在 python 解释器中时,import helloworld 仍然有效。我的 travis 测试失败了,因为我有一个测试检查编译后的 .so 文件的 name。如果我删除该测试,文件的其余部分应该仍然有效。

关于python - 在 Ubuntu Python 3 上构建的 Cython+distutils 在链接期间更改了模块库名称,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/25235013/

相关文章:

python - Openpyxl Python - Vlookup 遍历行

python - (出人意料地具有挑战性?)Numpy 向量化

python - cython pyximport 在哪里编译?

multithreading - Cython Prange失败并显示致命Python错误: PyThreadState_Get: no current thread

python - 测试 Python C 库 - 获取构建路径

python - 如何使用 distutils 指定 C++11?

python - 到底怎么回事...? Python C 代码创建的文件的文件权限

python - 值错误 : invalid literal for int() with base 10: b'1\n5\n'

python - Mongodb TTL 提前过期文档

python - Cython编译错误