最近在项目中想用 golang调用 python
在执行的时候一直报这个错
SyntaxError: invalid syntax (uuid.py, line 138)
demp.py内容
```
y = 6
import time
import uuid
def testF():
global y
y = y-2
print(uuid.uuid4())
return 2*y*time.time()*uuid.uuid4()
if __name__ == "__main__":
testF()
```
main.go 文件
```
package main
import (
"fmt"
"github.com/DataDog/go-python3"
)
func main() {
python3.Py_Initialize()
defer python3.Py_Finalize()
if !python3.Py_IsInitialized() {
panic("Error initializing the python interpreter")
}
var err error
err = python3.PySys_SetPath("/opt/gop/")
if err != nil {
panic("ERROR: Path set error.")
}
dir := "/usr/local/lib/python3.7/dist-packages"
python3.PyRun_SimpleString("import sys\nsys.path.append(\"" + dir + "\")")
pModule := python3.PyImport_ImportModule("test.demo.demo1")
if pModule == nil {
panic("ERROR: Module not found.")
}
}
```
执行报错内容
```
Traceback (most recent call last):
File "/opt/gopwn/test/demo/demo1.py", line 4, in <module>
import uuid
SyntaxError: invalid syntax (uuid.py, line 138)
panic: ERROR: Module not found.
goroutine 1 [running]:
```
不使用 uuid 插件就好,什么原因呢?