azev
V2EX  ›  问与答

把 Python 代码编译封装打包成 dll 以给 C#调用

  •  
  •   azev · Apr 10, 2024 · 1469 views
    This topic created in 764 days ago, the information mentioned may be changed or developed.

    是不是没有什么好的方法?各种途径了解到好像最终是 ctypes?但也相当难搞。
    是在一个百十来次的快速循环中调用,使用 subprocess.run()也不太行。

    6 replies    2024-04-10 15:30:48 +08:00
    yylxbiubiu
        1
    yylxbiubiu  
       Apr 10, 2024
    为什么不把 py 做成一个服务,打包成一个二进制封装进去
    Eiden
        2
    Eiden  
       Apr 10, 2024
    不能重写吗(
    wanguorui123
        3
    wanguorui123  
       Apr 10, 2024
    Socket 通讯
    ysc3839
        4
    ysc3839  
       Apr 10, 2024 via Android
    要 C# 作为入口启动,Python 作为 DLL 被加载的话,得用 Python 的 embed(嵌入式)模式。
    我不知道 C# 有没有相关库,C++ 的话可以用 pybind11 。
    ysc3839
        5
    ysc3839  
       Apr 10, 2024 via Android
    ctypes 是给 Python 调用别的 DLL 用的,大概不符合你的需求。

    另外我怀疑这是个 X-Y Problem https://coolshell.cn/articles/10804.html
    建议说清楚原始需求。
    R4rvZ6agNVWr56V0
        6
    R4rvZ6agNVWr56V0  
       Apr 10, 2024
    https://pythonnet.github.io/pythonnet/dotnet.html 或许可以解决你的问题/not
    About   ·   Help   ·   Advertise   ·   Blog   ·   API   ·   FAQ   ·   Solana   ·   3749 Online   Highest 6679   ·     Select Language
    创意工作者们的社区
    World is powered by solitude
    VERSION: 3.9.8.5 · 40ms · UTC 04:55 · PVG 12:55 · LAX 21:55 · JFK 00:55
    ♥ Do have faith in what you're doing.