go-python / gopy

gopy generates a CPython extension module from a go package.
BSD 3-Clause "New" or "Revised" License
2.05k stars 113 forks source link

hi example results in _hi.so vs hi.so #234

Closed shaolo1 closed 3 years ago

shaolo1 commented 4 years ago

Trying to get started with gopy, I'm stuck on the simple hi example.

gopy build -output=out github.com/go-python/gopy/_examples/hi

--- Processing package: github.com/go-python/gopy/_examples/hi ---

--- building package ---
gopy build -output=out github.com/go-python/gopy/_examples/hi
goimports -w hi.go
go build -buildmode=c-shared -o hi_go.so .
python build.py
go run patch-leaks.go hi.c # patch memory leaks in pybindgen output
go env CC
python-config --cflags
python-config --ldflags
gcc hi.c hi_go.so -o _hi.so -I/usr/include/python3.8 -I/usr/include/python3.8 -Wno-unused-result -Wsign-compare -g -fdebug-prefix-map=/build/python3.8-xhc1jt/python3.8-3.8.5=. -specs=/usr/share/dpkg/no-pie-compile.specs -fstack-protector -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O3 -Wall -L/usr/lib/python3.8/config-3.8-x86_64-linux-gnu -L/usr/lib -lcrypt -lpthread -ldl -lutil -lm -lm -fPIC --shared -Ofast
ls out
Makefile  __init__.py  __pycache__  _hi.so  build.py  go.py  hi.c  hi.go  hi.py  hi_go.h  hi_go.so  patch-leaks.go
root@3c91d87f0f54:/gopy_examples# cd out
root@3c91d87f0f54:/gopy_examples/out# python
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import hi
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/gopy_examples/out/hi.py", line 15, in <module>
    import _hi
ImportError: hi_go.so: cannot open shared object file: No such file or directory

trying the from python had a similar failure

root@3c91d87f0f54:/gopy_examples# python
Python 3.8.5 (default, Jul 28 2020, 12:59:40) 
[GCC 9.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gopy
>>> hi = gopy.load("github.com/go-python/gopy/_examples/hi")
gopy> inferring package name...
gopy> loading 'github.com/go-python/gopy/_examples/hi'...
gopy - 

Commands:

    build       generate and compile (C)Python language bindings for Go
    exe         generate and compile (C)Python language bindings for Go, and make a standalone python executable with all the code -- must provide suitable main function code
    gen         generate (C)Python language bindings for Go
    pkg         generate and compile (C)Python language bindings for Go, and make a python package

Use "gopy help <command>" for more information about a command.

gopy> importing 'github.com/go-python/gopy/_examples/hi'
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/root/go/src/github.com/go-python/gopy/gopy.py", line 49, in load
    ok = imp.find_module(n, [output])
  File "/usr/lib/python3.8/imp.py", line 296, in find_module
    raise ImportError(_ERR_MSG.format(name), name=name)
ImportError: No module named 'hi'
shaolo1 commented 4 years ago

I was looking at the readme.md pull request and saw "export LD_LIBRARY_PATH=$LD_LIBRARY_PATH:./" Adding that allowed the example to work. So I guess there is just a small problem with

From the command line

$ gopy build -output=out github.com/go-python/gopy/_examples/hi
$ ls out
hi.so

should show

$ ls out
Makefile  __init__.py  __pycache__  _hi.so  build.py  go.py  hi.c  hi.go  hi.py  hi_go.h  hi_go.so  patch-leaks.go

I was thrown off since hi.so was not there.