DataDog / go-python3

Go bindings to the CPython-3 API
MIT License
376 stars 140 forks source link

Undefined reference to 'Py_True' #41

Closed Mingmingchina1996 closed 3 years ago

Mingmingchina1996 commented 3 years ago

Describe what happened: I got the following errors when I use 'go get github.com/DataDog/go-python3' to install this package on Ubuntu: /tmp/go-build990175588/github.com/DataDog/go-python3/_obj/_cgo_main.o:(.data.rel+0x0):undefined reference to 'Py_True' /tmp/go-build990175588/github.com/DataDog/go-python3/_obj/_cgo_main.o:(.data.rel+0x8):undefined reference to 'Py_None' /tmp/go-build990175588/github.com/DataDog/go-python3/_obj/_cgo_main.o:(.data.rel+0x10):undefined reference to 'Py_False'

christian-korneck commented 3 years ago

@Mingmingchina1996 are you using Python3.7 (which is the only one supported python version of go-python3)? Depending on the Ubuntu version you might need to get a different Python version than from the official OS packages. Here's an example for doing that on Debian, which should be roughly similar to Ubuntu.

Mingmingchina1996 commented 3 years ago

@Mingmingchina1996 are you using Python3.7 (which is the only one supported python version of go-python3)? Depending on the Ubuntu version you might need to get a different Python version than from the official OS packages. Here's an example for doing that on Debian, which should be roughly similar to Ubuntu.

I am using python3.7.10. maybe I should try install it with docker

christian-korneck commented 3 years ago

you don't need docker, this works for me on Ubuntu 20.04:

cd $HOME
sudo su
apt-get -y update && apt-get -y install curl build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev git curl pkg-config gcc golang
curl https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tgz -o python.tgz && tar xf python.tgz
cd Python-3.7.10
./configure --enable-shared --prefix=/opt/py
make -j `nproc`
make install
echo /opt/py/lib > /etc/ld.so.conf.d/py.conf && ldconfig
export PKG_CONFIG_PATH=/opt/py/lib/pkgconfig
cd $HOME
mkdir hello
cd hello
curl -L https://raw.githubusercontent.com/christian-korneck/Dockerfiles/master/debian-go-python3-demo/hello/main.go -o main.go
go mod init hello
go mod tidy
go get .
go build -o /opt/hello/bin/hello .

and then run it:

$ /opt/hello/bin/hello
hello from python in go
Mingmingchina1996 commented 3 years ago

you don't need docker, this works for me on Ubuntu 20.04:

cd $HOME
sudo su
apt-get -y update && apt-get -y install curl build-essential zlib1g-dev libncurses5-dev libgdbm-dev libnss3-dev libssl-dev libreadline-dev libffi-dev git curl pkg-config gcc golang
curl https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tgz -o python.tgz && tar xf python.tgz
cd Python-3.7.10
./configure --enable-shared --prefix=/opt/py
make -j `nproc`
make install
echo /opt/py/lib > /etc/ld.so.conf.d/py.conf && ldconfig
export PKG_CONFIG_PATH=/opt/py/lib/pkgconfig
cd $HOME
mkdir hello
cd hello
curl -L https://raw.githubusercontent.com/christian-korneck/Dockerfiles/master/debian-go-python3-demo/hello/main.go -o main.go
go mod init hello
go mod tidy
go get .
go build -o /opt/hello/bin/hello .

and then run it:

$ /opt/hello/bin/hello
hello from python in go

With your instruction, I have solved this issue. Thank you very much