go调用python3

因为python的底层c写的,只需要让go可以调用c就能调用python了

import "github.com/DataDog/go-python3"
/*
#cgo CFLAGS: "-I/usr/include/python3.8"
#cgo LDFLAGS: "-L/usr/local/lib/python3.8" "-lpython3.8"
#define PY_SSIZE_T_CLEAN
#include <Python.h>
*/
pycodeGo := `
from you_get import common
video_url = "` + video_url + `"
res = common.any_download(url=video_url,json_output=True)
output['title'] = res['title']
output['url'] = res['streams']['18']['url']
print(output)
`

defer python3.Py_Finalize()
python3.Py_Initialize()
pyResult := python3.PyRun_SimpleString(pycodeGo)

github上有2个python的项目,一个python2,一个python3

python2:https://github.com/sbinet/go-python

python3:https://github.com/DataDog/go-python3

发表回复

您的邮箱地址不会被公开。 必填项已用 * 标注