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
xiaochuaner
V2EX  ›  Python

2023 年,使用 Python 封装 C 语言库的最佳选择是什么?

  •  
  •   xiaochuaner · 294 天前 · 2540 次点击
    这是一个创建于 294 天前的主题,其中的信息可能已经有所发展或是发生改变。

    目标是一个算法加速库,使用 C + 汇编写成,,希望把接口经 Python 封装后打包成一个 Python 库,现在最适合的技术选型是什么呢?

    1. ctypes
    2. Cython
    3. pybind
    4. SWIG
    5. cffi

    13 条回复    2023-07-08 16:12:43 +08:00
    t133
        1
    t133  
       294 天前 via iPhone
    F2py
    t133
        2
    t133  
       294 天前 via iPhone
    @t133 不好意思你说的是 C 走错片场了
    Rang666
        3
    Rang666  
       294 天前 via iPhone
    可以看一下 numpy ,tf 这种咋弄的,不过我自己弄就直接 dll 之类的。cython 能和 cpp 连吗?我记得是要单独一套语言吧?
    RuiCBai
        4
    RuiCBai  
       294 天前 via Android
    pybind11 ,pytorch 官方推荐
    hsfzxjy
        5
    hsfzxjy  
       294 天前 via Android
    pybind11 或者直接 C 手撸
    dayeye2006199
        6
    dayeye2006199  
       294 天前 via Android
    pybind11 加一票
    GeruzoniAnsasu
        7
    GeruzoniAnsasu  
       294 天前
    多前端(保持 C ABI ) => CFFI
    只用作 py 的扩展库 => pybind
    qq565425677
        8
    qq565425677  
       294 天前
    记得 numpy 好像用的是 cython ?
    Lychee0
        9
    Lychee0  
       294 天前
    pybind11 加一票
    tangtang369
        10
    tangtang369  
       294 天前
    pybind11 肯定是这个 但是越来越多后 感觉和 c 又没啥关联了 大家都知道 numpy 是 c 写的 但是 c 并没有个和 python 一样 numpy 直接就能用的
    roundgis
        11
    roundgis  
       294 天前 via Android
    @Rang666 numpy 現在應該還是用 cython
    clino
        12
    clino  
       294 天前
    我问了 chatgpt 和 claude 都回答说 cython ,原来 cython 还能包装 c 库,给了个例子一看确实比较简单
    inframe
        13
    inframe  
       294 天前
    pybind11 ,或者 cython
    关于   ·   帮助文档   ·   博客   ·   API   ·   FAQ   ·   我们的愿景   ·   实用小工具   ·   988 人在线   最高记录 6543   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 27ms · UTC 19:20 · PVG 03:20 · LAX 12:20 · JFK 15:20
    Developed with CodeLauncher
    ♥ Do have faith in what you're doing.