推荐学习书目
› Learn Python the Hard Way
Python Sites
› PyPI - Python Package Index
› http://diveintopython.org/toc/index.html
› Pocoo
值得关注的项目
› PyPy
› Celery
› Jinja2
› Read the Docs
› gevent
› pyenv
› virtualenv
› Stackless Python
› Beautiful Soup
› 结巴中文分词
› Green Unicorn
› Sentry
› Shovel
› Pyflakes
› pytest
Python 编程
› pep8 Checker
Styles
› PEP 8
› Google Python Style Guide
› Code Style from The Hitchhiker's Guide
KADGang
V2EX  ›  Python

请教一下各位 V 友关于 Pybind11 封装 Python 接口, pyd 库对于各个版本的 Python 的兼容问题

  •  
  •   KADGang · Oct 20, 2023 · 2422 views
    This topic created in 1075 days ago, the information mentioned may be changed or developed.

    目前我使用 CMake+Pybind11 来封装 Python 接口,在封装过程中我发现一个问题,如果我使用的 python 环境为 3.7 ,那么封装后的 pyd 库只能在 3.7 的解释器下面运行,如果在 3.8 或者其他版本下 import 的时候会报 DLL 错误。目前打算支持 3.7 以上的 python 版本,那么请教各位大佬如何处理这种版本不兼容的问题?

    5 replies  •  2023-10-21 00:42:18 +08:00
    lovelylain
        1
    lovelylain  
       Oct 20, 2023 via Android   ❤️ 1
    python 扩展一直都是这样的,要针对特定 python 版本单独编译,因为不同版本 api 可能有差异,不想放出源码让用户安装时编译的话你就预先编译好所有期望平台期望版本的 wheel 包。
    nightwitch
        2
    nightwitch  
       Oct 20, 2023   ❤️ 1
    做不到,Python 的通病。
    https://pypi.org/project/numpy/#files
    可以看一下 numpy 打一个版本要打多少种不同的变体
    ysc3839
        3
    ysc3839  
       Oct 20, 2023 via Android   ❤️ 1
    只能单独编译。或者你可以直接调 Python 的 C 接口,有一套好像叫 Python min 还是 Python base 的接口?可以整个大版本通用,但是会缺少很多新功能,写起来超级麻烦,反正 pybind11 是用不了的。
    aisk
        4
    aisk  
       Oct 20, 2023   ❤️ 1
    如果接口交互简单,直接用 ctypes / cffi 调用暴露出来的 C 接口,然后发布一个 .so ,最简单。
    ysc3839
        5
    ysc3839  
       Oct 21, 2023 via Android
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Privacy   ·   Solana   ·   5253 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 33ms · UTC 03:05 · PVG 11:05 · LAX 20:05 · JFK 23:05
    ♥ Do have faith in what you're doing.