gopy: Can't setup gopy to work

I can’t get gopy works even with python console, bash or docker. Tried all examples from README

go version go1.13.1 linux/amd64 ubuntu 16.04 Python 3.6.8

  1. gopy build + console
$ python
Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) 
[GCC 7.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 "/home/kistler/go-sdk/out/hi.py", line 15, in <module>
    import _hi
ImportError: hi_go.so: cannot open shared object file: No such file or directory
>>> 
  1. python console
Python 3.6.8 |Anaconda, Inc.| (default, Dec 30 2018, 01:22:34) 
[GCC 7.3.0] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import gopy
>>> gopy.load()
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
AttributeError: module 'gopy' has no attribute 'load'
>>> 
  1. docker
docker build --network=host -t go-python/gopy .
Sending build context to Docker daemon  4.836MB
Step 1/3 : FROM golang:onbuild
# Executing 3 build triggers
 ---> Using cache
 ---> Running in 921b4192dcac
+ exec go get -v -d
github.com/go-python/gopy (download)
github.com/pkg/errors (download)
github.com/gonuts/commander (download)
github.com/gonuts/flag (download)
Fetching https://golang.org/x/tools/go/packages?go-get=1
Parsing meta tags from https://golang.org/x/tools/go/packages?go-get=1 (status code 200)
get "golang.org/x/tools/go/packages": found meta tag main.metaImport{Prefix:"golang.org/x/tools", VCS:"git", RepoRoot:"https://go.googlesource.com/tools"} at https://golang.org/x/tools/go/packages?go-get=1
get "golang.org/x/tools/go/packages": verifying non-authoritative meta tag
Fetching https://golang.org/x/tools?go-get=1
Parsing meta tags from https://golang.org/x/tools?go-get=1 (status code 200)
golang.org/x/tools (download)
Removing intermediate container 921b4192dcac
 ---> Running in 1cac7d2530d9
+ exec go install -v
github.com/pkg/errors
golang.org/x/tools/go/internal/gcimporter
github.com/gonuts/flag
golang.org/x/tools/go/internal/packagesdriver
golang.org/x/tools/internal/fastwalk
golang.org/x/tools/internal/semver
golang.org/x/tools/internal/span
golang.org/x/tools/internal/gopathwalk
# golang.org/x/tools/go/internal/packagesdriver
../golang.org/x/tools/go/internal/packagesdriver/sizes.go:107: undefined: types.SizesFor
github.com/go-python/gopy/bind
# golang.org/x/tools/go/internal/gcimporter
../golang.org/x/tools/go/internal/gcimporter/bexport.go:212: obj.IsAlias undefined (type *types.TypeName has no field or method IsAlias)
../golang.org/x/tools/go/internal/gcimporter/iexport.go:234: obj.IsAlias undefined (type *types.TypeName has no field or method IsAlias)
github.com/gonuts/commander
# github.com/go-python/gopy/bind
../github.com/go-python/gopy/bind/symbols.go:134: f.Embedded undefined (type *types.Var has no field or method Embedded)
../github.com/go-python/gopy/bind/symbols.go:1001: f.Embedded undefined (type *types.Var has no field or method Embedded)
../github.com/go-python/gopy/bind/types.go:133: f.Embedded undefined (type *types.Var has no field or method Embedded)
The command '/bin/sh -c go-wrapper install' returned a non-zero code: 2

I will appreciate any help!

About this issue

  • Original URL
  • State: closed
  • Created 5 years ago
  • Reactions: 3
  • Comments: 17 (6 by maintainers)

Most upvoted comments

Sorry for not being able to look at this – from what I can tell, the underlying issue is the linker not being able to find the .so files. This has to be solved by adding the proper path to LD_LIBRARY_PATH at some level, and by finding exactly where the .so files are, this should be solvable, at least at a workaround level.

I will try to boot up my linux system at some point soon and see if I can provide some further insight. I haven’t really run gopy on anything other than my mac at this point… Sorry very busy this quarter.

@robooo @HuiiBuh I am unsure of the exact reason, but I was helping a friend with a similar issue as in 1. For him, it was something with the LD path. Maybe it could be an issue with not looking locally or some python configuration issue. I am unsure.

The following should be a hack to make it work. Try this and see if it helps.

LD_LIBRARY_PATH=$LD_LIBRARY_PATH:$PWD python

@rcoreilly @sbinet When you have time, please have a look at this issue.

I am also trying to figure out how the tests are running and passing in the CI. Tried this (on both Debian Buster + Python3.7 and Ubuntu Xenial + Python3.5).

root@17a6aa2bb974:~/gocode/src/github.com/kushaldas/garam# gopy build -output=/tmp/output -vm=/usr/bin/python3 github.com/kushaldas/garam/pkg/madeingo

--- Processing package: github.com/kushaldas/garam/pkg/madeingo ---

--- building package ---
gopy build -output=/tmp/output -vm=/usr/bin/python3 github.com/kushaldas/garam/pkg/madeingo
goimports -w madeingo.go
go build -buildmode=c-shared -o madeingo_go.so .
/usr/bin/python3 build.py
go run patch-leaks.go madeingo.c # patch memory leaks in pybindgen output
go env CC
/usr/bin/python3-config --cflags
/usr/bin/python3-config --ldflags
gcc madeingo.c madeingo_go.so -o _madeingo.so -I/usr/include/python3.5m -I/usr/include/python3.5m -Wno-unused-result -Wsign-compare -g -fstack-protector-strong -Wformat -Werror=format-security -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -L/usr/lib/python3.5/config-3.5m-x86_64-linux-gnu -L/usr/lib -lpython3.5m -lpthread -ldl -lutil -lm -Xlinker -export-dynamic -Wl,-O1 -Wl,-Bsymbolic-functions -fPIC --shared -Ofast
root@17a6aa2bb974:~/gocode/src/github.com/kushaldas/garam# cd /tmp/output/
root@17a6aa2bb974:/tmp/output# ls
Makefile  __init__.py  _madeingo.so  build.py  go.py  madeingo.c  madeingo.go  madeingo.py  madeingo_go.h  madeingo_go.so  patch-leaks.go
root@17a6aa2bb974:/tmp/output# python3
Python 3.5.2 (default, Oct  8 2019, 13:06:37) 
[GCC 5.4.0 20160609] on linux
Type "help", "copyright", "credits" or "license" for more information.
>>> import madeingo
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/tmp/output/madeingo.py", line 12, in <module>
    import _madeingo
ImportError: madeingo_go.so: cannot open shared object file: No such file or directory
>>> 
root@17a6aa2bb974:/tmp/output# ldd _madeingo.so 
	linux-vdso.so.1 =>  (0x00007ffc4306a000)
	madeingo_go.so => not found
	libpython3.5m.so.1.0 => /usr/lib/x86_64-linux-gnu/libpython3.5m.so.1.0 (0x00007f7daad9e000)
	libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7daa9d4000)
	libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7daa7b7000)
	libexpat.so.1 => /lib/x86_64-linux-gnu/libexpat.so.1 (0x00007f7daa58e000)
	libz.so.1 => /lib/x86_64-linux-gnu/libz.so.1 (0x00007f7daa374000)
	libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7daa170000)
	libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f7da9f6d000)
	libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7da9c64000)
	/lib64/ld-linux-x86-64.so.2 (0x00007f7dab631000)

If I just copy the madeingo_go.so or hi_go.so in our main example to the right path (/usr/lib), the system can find the right shared library file. But, otherwise it can not. Any help on this will be really helpful.