V2EX = way to explore
V2EX 是一个关于分享和探索的地方
现在注册
已注册用户请  登录
推荐学习书目
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 · 194 天前 · 967 次点击
    这是一个创建于 194 天前的主题,其中的信息可能已经有所发展或是发生改变。

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

    5 条回复    2023-10-21 00:42:18 +08:00
    lovelylain
        1
    lovelylain  
       194 天前 via Android   ❤️ 1
    python 扩展一直都是这样的,要针对特定 python 版本单独编译,因为不同版本 api 可能有差异,不想放出源码让用户安装时编译的话你就预先编译好所有期望平台期望版本的 wheel 包。
    nightwitch
        2
    nightwitch  
       193 天前   ❤️ 1
    做不到,Python 的通病。
    https://pypi.org/project/numpy/#files
    可以看一下 numpy 打一个版本要打多少种不同的变体
    ysc3839
        3
    ysc3839  
       193 天前 via Android   ❤️ 1
    只能单独编译。或者你可以直接调 Python 的 C 接口,有一套好像叫 Python min 还是 Python base 的接口?可以整个大版本通用,但是会缺少很多新功能,写起来超级麻烦,反正 pybind11 是用不了的。
    aisk
        4
    aisk  
       193 天前   ❤️ 1
    如果接口交互简单,直接用 ctypes / cffi 调用暴露出来的 C 接口,然后发布一个 .so ,最简单。
    ysc3839
        5
    ysc3839  
       193 天前 via Android
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   2182 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 25ms · UTC 11:31 · PVG 19:31 · LAX 04:31 · JFK 07:31
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.