Created
February 1, 2023 19:43
-
-
Save gucio321/ca95078b270fa6153d89184ee6e7ea3d to your computer and use it in GitHub Desktop.
Simple example of GO code running Python 3.11 (works at leas on Fedora 37)
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
package main | |
// #cgo pkg-config: python3-embed | |
// #include <Python.h> | |
import "C" | |
import ( | |
"unsafe" | |
) | |
func main() { | |
pycodeGo := ` | |
import sys | |
for path in sys.path: | |
print(path) | |
` | |
defer C.Py_Finalize() | |
C.Py_Initialize() | |
pycodeC := C.CString(pycodeGo) | |
defer C.free(unsafe.Pointer(pycodeC)) | |
C.PyRun_SimpleString(pycodeC) | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment