【问题标题】:Linux platform tag for python module built with pybind11使用 pybind11 构建的 python 模块的 Linux 平台标签
【发布时间】:2018-04-01 15:08:22
【问题描述】:

我正在使用 pybind11 并使用 setuptools 和 cmake 构建 python 模块,如pybind/cmake_example 中所述:

setup(
    name='libraryname',
    ...
    ext_modules=[CMakeExtension('libraryname')],
    cmdclass=dict(build_ext=CMakeBuild),
)

在本地,使用 python setup.py sdist build 一切都很好,我可以使用和/或从生成的文件安装包。

我现在想将包上传到 PyPI。 从不同的 python 包中,我知道如何通过操作轮子的平台标签来生成通用的 linux 库(另请参见here):

class bdist_wheel(bdist_wheel_):
    def finalize_options(self):
        from sys import platform as _platform
        platform_name = get_platform()
        if _platform == "linux" or _platform == "linux2":
            # Linux
            platform_name = 'manylinux1_x86_64'

        bdist_wheel_.finalize_options(self)
        self.universal = True
        self.plat_name_supplied = True
        self.plat_name = platform_name

setup(
    ...
    cmdclass = {'bdist_wheel': bdist_wheel},
)

问题:

没有bdist_wheel构建时如何生成合适的平台标签? 这是否应该以某种方式构建为轮子而不是扩展(可能与this issue on GH 相关)?

另外,pybind11 是如何决定生成库的后缀的(在我的 linux 上不只是.so,而是.cpython-35m-x86_64-linux-gnu.so)?

跟进:

  • 主要问题是我无法将当前 Ubuntu 构建的包更新为 PyPI:ValueError: Unknown distribution format: 'libraryname-0.8.0.cpython-35m-x86_64-linux-gnu.so'
  • 如果平台标签不能或不应更改:跨平台将 pybind11 模块上传到 PyPI 的最佳做法是什么?

【问题讨论】:

    标签: c++ python-3.x pypi pybind11


    【解决方案1】:

    我的错!

    事实证明,这种混乱是由于我最初尝试运行 python setup.py sdist bdist_wheel 时遇到的构建错误造成的。 使用 python setup.py build 手动构建不是发布包的正确方法。

    注意: .so 文件的名称需要设置为不带 -0.8.0 版本标识符,以便 python 能够从轮子进行导入。

    总结: 构建和发布二进制轮子的工作方式与 pybind11 完全相同,例如cpython,它应该可以很好地遵循pybind/cmake_example

    【讨论】:

      猜你喜欢
      • 2010-12-09
      • 2019-01-25
      • 2022-12-02
      • 1970-01-01
      • 2020-08-28
      • 1970-01-01
      • 2013-06-05
      • 2016-07-24
      • 2018-08-23
      相关资源
      最近更新 更多