python - 如何从 Python 调用 Go 函数

标签 python go .so

我正在尝试从 python 调用 go lang 函数 当我调用我的 python 程序时,我看到以下错误。 我指的是 Go to pythn关联。

error

Python程序

    from ctypes import *
    def call_go_function():

        lib = cdll.LoadLibrary("./awesome.so")
        lib.Add.argtypes = [c_longlong, c_longlong]
        print( lib.Add(12,99)) 

    call_go_function()   

Go程序

package main
import "C"
import (

"sync"
 )
 var count int
 var mtx sync.Mutex
 //export Add
 func Add(a, b int) int { return a + b }
 func main() {}

最佳答案

从 Python 路径看,这是一个 32 位 Python 版本。您不能混合使用 32 位和 64 位用户空间代码。

所以我猜你需要:

  • 将您的 Go 代码重建为 32 位 DLL(参见 GOARCH=386)或
  • 安装并运行 64 位 Python 版本。

关于python - 如何从 Python 调用 Go 函数,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/57105879/

相关文章:

elasticsearch - DeleteByQuery ElasticSearch Golang 错误 elastic : Error 404 (Not Found)

c++ - 为什么在这种情况下编译动态库会出错呢?

eclipse - 在 Eclipse 上链接 .so 文件

c++ - 编译几个源文件(主文件和头文件)并在 ROOT CINT 中链接它们?

python - 在 pandas 中,我如何为 datetime 列分组 weekday() ?

python - TensorFlow 1.5.0-rc0 : error using `tf.app.flags`

python - pyodbc的 `Cursor.execute`返回哪个游标对象?

go - 如何定义 `const *DataType`

python - Pandas 中的Groupby列后缀

xml - 在golang中解析xml文本