我正在使用 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 的最佳做法是什么?
最佳答案
我的错!
事实证明,混淆是由于我最初尝试运行 python setup.py sdist bdist_wheel
时遇到的构建错误造成的。
使用 python setup.py build
手动构建不是发布包的正确方法。
注意:需要设置 .so 文件的名称而不带 -0.8.0
版本标识符,以便 python 能够从轮子。
总结: 构建和发布二进制轮子与 pybind11 的工作方式完全相同,例如cpython 并且它应该可以很好地遵循 pybind/cmake_example .
关于c++ - 使用 pybind11 构建的 python 模块的 Linux 平台标签,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/46849195/