You signed in with another tab or window. Reload to refresh your session.You signed out in another tab or window. Reload to refresh your session.You switched accounts on another tab or window. Reload to refresh your session.Dismiss alert
{{ message }}
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.
Describe what happened:
the first line of py code from xxx import play
Describe what you expected:
the xxx is a so file.
Run the py script in command line is fine
Steps to reproduce the issue:
I read the the py script as string in go named code ,then python3.PyRun_SimpleString(code)
Not work , ModuleNotFoundError: no module named 'xxx'
The text was updated successfully, but these errors were encountered:
the path to the dir that contains the python module that you want to import needs to be in Python's sys.path list.
You can print the list with something like:
pycode := `
import sys
for path in sys.path:
print(path)
`
python3.PyRun_SimpleString(pycode)
and also append a missing path, if needed
dir := "/some/custom/site-packages"
python3.PyRun_SimpleString("import sys\nsys.path.append(\"" + dir + "\")")
Here's a more complete example that adds the same path as the compiled Go program:
dir, err := filepath.Abs(filepath.Dir(os.Args[0]))
if err != nil {
log.Fatal(err)
}
ret := python3.PyRun_SimpleString("import sys\nsys.path.append(\"" + dir + "\")")
if ret != 0 {
log.Fatalf("error appending '%s' to python sys.path", dir)
}
for completeness: instead of doing this in a PyRun_SimpleString() (which only has limited error handling) you could also use PySys_GetObject("path") + PySys_SetPath().
Describe what happened:
the first line of py code
from xxx import play
Describe what you expected:
the xxx is a so file.
Run the py script in command line is fine
Steps to reproduce the issue:
I read the the py script as string in go named
code
,thenpython3.PyRun_SimpleString(code)
Not work , ModuleNotFoundError: no module named 'xxx'
The text was updated successfully, but these errors were encountered: