duanpo1821 2019-07-19 05:10
浏览 432

如何从Python调用Go函数

I am trying to call go lang function from python when I call my python program I am seeing the following error. I am referring to the Go to pythn link.

error

Python Program

    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 Program

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() {}
  • 写回答

1条回答 默认 最新

  • dqc19941228 2019-07-19 11:24
    关注

    From the Python path it looks like this is a 32-bit Python version. You cannot mix 32-bit and 64-bit user-space code.

    So I guess you need to either:

    • Rebuild your Go code as a 32-bit DLL (see GOARCH=386) or
    • Install and run a 64-bit Python version.
    评论

报告相同问题?

悬赏问题

  • ¥15 stable diffusion
  • ¥100 Jenkins自动化部署—悬赏100元
  • ¥15 关于#python#的问题:求帮写python代码
  • ¥20 MATLAB画图图形出现上下震荡的线条
  • ¥15 关于#windows#的问题:怎么用WIN 11系统的电脑 克隆WIN NT3.51-4.0系统的硬盘
  • ¥15 perl MISA分析p3_in脚本出错
  • ¥15 k8s部署jupyterlab,jupyterlab保存不了文件
  • ¥15 ubuntu虚拟机打包apk错误
  • ¥199 rust编程架构设计的方案 有偿
  • ¥15 回答4f系统的像差计算