Tuesday, April 23, 2024
HomeGolangUse python in GO code - Code Evaluation

Use python in GO code – Code Evaluation


Hello!
I want to make use of python code in go.
I wrote the next instance however I’m unable to run it:

package deal important

// #cgo pkg-config: python3
// #embrace "/usr/embrace/python3.11/Python.h"
import "C"
import "fmt"

func important() {
	C.Py_Initialize()
	fmt.Println(C.GoString(C.Py_GetVersion()))
	C.Py_Finalize()
}
ld panic
# command-line-arguments
/usr/native/go/pkg/instrument/linux_amd64/hyperlink: operating gcc failed: exit standing 1
/usr/bin/ld: /tmp/go-link-3756148642/000001.o: in operate `_cgo_d10853a22200_Cfunc_Py_GetVersion':
/tmp/go-build/cgo-gcc-prolog:63: undefined reference to `Py_GetVersion'
/usr/bin/ld: /tmp/go-link-3756148642/000001.o: in operate `_cgo_d10853a22200_Cfunc_Py_Finalize':
/tmp/go-build/cgo-gcc-prolog:49: undefined reference to `Py_Finalize'
/usr/bin/ld: /tmp/go-link-3756148642/000001.o: in operate `_cgo_d10853a22200_Cfunc_Py_Initialize':
/tmp/go-build/cgo-gcc-prolog:78: undefined reference to `Py_Initialize'
collect2: error: ld returned 1 exit standing

OS: Fedora launch 37 (Thirty Seven)
Go: go model go1.19.5 linux/amd64
Python: Python 3.11.1
gcc: gcc (GCC) 12.2.1 20221121 (Purple Hat 12.2.1-4)

I’m guessing Go can’t discover libpython3. What does your python3.computer file appear like?

@skillian right here is content material of /usr/lib64/pkgconfig/python3.computer:

# See: man pkg-config
prefix=/usr
exec_prefix=/usr
libdir=/usr/lib64
includedir=/usr/embrace

Identify: Python
Description: Construct a C extension for Python
Requires:
Model: 3.11
Libs.non-public: -ldl 
Libs:
Cflags: -I${includedir}/python3.11

RELATED ARTICLES

LEAVE A REPLY

Please enter your comment!
Please enter your name here

Most Popular

Recent Comments