Exécuter du code python avec go lang

Voir :

https://www.slingacademy.com/article/how-to-run-python-code-with-go/

Voir aussi :

Inclure des appels à Go lang dans Python

Pb 1

$ go build py.go
# command-line-arguments
./py.go:3:11: fatal error: Python.h: No such file or directory
3 | // #include <Python.h>
| ^~~~~~

Solution

export C_INCLUDE_PATH=/usr/include/python3.13/

Pb 2

$ LANG=C go build py.go
# command-line-arguments
/usr/lib/go-1.26/pkg/tool/linux_amd64/link: running x86_64-linux-gnu-gcc failed: exit status 1
/usr/bin/x86_64-linux-gnu-gcc -m64 -Wl,--build-id=0x93e927a0e727ab54037ec0b3c85116f34e35a1b2 -o $WORK/b001/exe/a.out -Wl,--export-dynamic-symbol=_cgo_panic -Wl,--export-dynamic-symbol=_cgo_topofstack -Wl,--export-dynamic-symbol=crosscall2 -Wl,--compress-debug-sections=zlib /tmp/go-link-256395171/go.o /tmp/go-link-256395171/000000.o /tmp/go-link-256395171/000001.o /tmp/go-link-256395171/000002.o /tmp/go-link-256395171/000003.o /tmp/go-link-256395171/000004.o /tmp/go-link-256395171/000005.o /tmp/go-link-256395171/000006.o /tmp/go-link-256395171/000007.o /tmp/go-link-256395171/000008.o /tmp/go-link-256395171/000009.o /tmp/go-link-256395171/000010.o /tmp/go-link-256395171/000011.o /tmp/go-link-256395171/000012.o /tmp/go-link-256395171/000013.o /tmp/go-link-256395171/000014.o /tmp/go-link-256395171/000015.o /tmp/go-link-256395171/000016.o -O2 -g -O2 -g -lpthread -no-pie
/usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/go-link-256395171/000001.o: in function `_cgo_0270074b3d42_Cfunc_PyRun_SimpleString':
/tmp/go-build/cgo-gcc-prolog:55:(.text+0x15): undefined reference to `PyRun_SimpleStringFlags'
/usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/go-link-256395171/000001.o: in function `_cgo_0270074b3d42_Cfunc_Py_Finalize':
/tmp/go-build/cgo-gcc-prolog:67:(.text+0x31): undefined reference to `Py_Finalize'
/usr/bin/x86_64-linux-gnu-ld.bfd: /tmp/go-link-256395171/000001.o: in function `_cgo_0270074b3d42_Cfunc_Py_Initialize':
/tmp/go-build/cgo-gcc-prolog:76:(.text+0x41): undefined reference to `Py_Initialize'
collect2: error: ld returned 1 exit status