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 was archived by the owner on Aug 10, 2022. It is now read-only.
Repository navigation
This repository was archived by the owner on Aug 10, 2022. It is now read-only.
go-python3 works fine for me on Debian 10. In my setup the env var PKG_CONFIG_PATH points to a dir with a file exactly named python3.pc (I needed to create a symlink with that name).
Here's a Debian 10 Dockerfile example that works for me (even if you don't use Docker you should find the relevant parts in there):
FROM docker.io/library/debian:10
RUN apt-get -y update
RUN apt-get -y install golang python3.7 python3.7-dev pkg-config libpython3.7 libpython3.7-dev git
RUN ln -s /usr/lib/x86_64-linux-gnu/pkgconfig/python-3.7.pc /usr/lib/x86_64-linux-gnu/pkgconfig/python3.pc
ENV PKG_CONFIG_PATH=/usr/lib/x86_64-linux-gnu/pkgconfig
COPY hello /hello
RUN cd /hello && go get . && go build -o /usr/local/bin/hello .
CMD hello
(hello is a go program that prints a python string, all files are here).
quickstart:
$ git clone https://github.com/christian-korneck/Dockerfiles
$ cd Dockerfiles/debian-go-python3-demo/
$ docker build -t hello-demo .
$ docker run --rm hello-demo
hello from python in go
Hi, @christian-korneck , thank you very much for your patient.
I use debian 9 dokcer base image, python3.4 already installed on it. I can not changed to debian 10 for some reasons. And I noticed that apt-get install python3.7 and python3.7-dev not works( Couldn't find any package by regex 'python3.7-dev'), I've tried some ways to make it works such as add ppa, all failed.
finally, I installed python3.7 by wget python3.7 source code and compile it. but go-python3 compile still failed(have set the PKG_CONFIG_PATH env). I think it is because python3.7-dev is not installed in my docker image, but I can not figure out how to install it even after google it for several days.
for building python did you use configure --enable-shared? (this gives a working <prefix>/lib/pkgconfig/python3.pc) I just tried on Debian 9 and this Dockerfile works for me:
I've split this into three build steps. The first one builds python from src, the second one builds the go program against our custom python and the third one is for running the compiled Go program (a more minimal container with no build tools installed and both our go program and our custom python in /opt). You could of course also all do it in one container or machine.
# temp container to build python from source
FROM docker.io/library/debian:9 as builder-python
RUN 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
RUN curl https://www.python.org/ftp/python/3.7.10/Python-3.7.10.tgz -o python.tgz && tar xf python.tgz
RUN cd Python-3.7.10 && ./configure --enable-shared --prefix=/opt/py
RUN cd Python-3.7.10 && make -j `nproc`
RUN cd Python-3.7.10 && make install
# temp container to build the go program
FROM docker.io/library/debian:9 as builder-golang
COPY --from=builder-python /opt/py /opt/py
RUN echo /opt/py/lib > /etc/ld.so.conf.d/py.conf && ldconfig
RUN apt-get -y update && apt-get -y install git curl pkg-config gcc
RUN curl -L https://golang.org/dl/go1.16.2.linux-amd64.tar.gz -o go.tar.gz && tar -C /usr/local -xzf go.tar.gz
ENV PKG_CONFIG_PATH=/opt/py/lib/pkgconfig
COPY hello /hello
RUN cd /hello && /usr/local/go/bin/go get . && /usr/local/go/bin/go build -o /opt/hello/bin/hello .
# container to distribute the go program
FROM docker.io/library/debian:9-slim
COPY --from=builder-golang /opt/py /opt/py
COPY --from=builder-golang /opt/hello /opt/hello
RUN echo /opt/py/lib > /etc/ld.so.conf.d/py.conf && ldconfig
CMD /opt/hello/bin/hello
To try:
$ git clone https://github.com/christian-korneck/Dockerfiles
$ cd Dockerfiles/debian-go-python3-demo/
$ docker build -t hello-debian9 -f ./Dockerfile.debian9 .
$ docker run --rm hello-debian9
hello from python in go
hi @christian-korneck ,i had the same problem ,and i used pyenv to install the python3.7 with options configure --enable-shared.but it still doesnt work. i can't use docker. thanks for your help~
os:ubuntu 20.04
Activity
christian-korneck commentedon Mar 12, 2021
hi @YangChuanMakeSense,
go-python3works fine for me on Debian 10. In my setup the env varPKG_CONFIG_PATHpoints to a dir with a file exactly namedpython3.pc(I needed to create a symlink with that name).Here's a Debian 10 Dockerfile example that works for me (even if you don't use Docker you should find the relevant parts in there):
(
hellois a go program that prints a python string, all files are here).quickstart:
Hope this helps.
YangChuanMakeSense commentedon Mar 14, 2021
Hi, @christian-korneck , thank you very much for your patient.
I use debian 9 dokcer base image, python3.4 already installed on it. I can not changed to debian 10 for some reasons. And I noticed that
apt-get install python3.7andpython3.7-devnot works(Couldn't find any package by regex 'python3.7-dev'), I've tried some ways to make it works such as addppa, all failed.finally, I installed python3.7 by wget python3.7 source code and compile it. but
go-python3compile still failed(have set the PKG_CONFIG_PATH env). I think it is because python3.7-dev is not installed in my docker image, but I can not figure out how to install it even after google it for several days.I am very appreciate for your help
christian-korneck commentedon Mar 14, 2021
hi @YangChuanMakeSense ,
for building python did you use
configure --enable-shared? (this gives a working<prefix>/lib/pkgconfig/python3.pc) I just tried on Debian 9 and thisDockerfileworks for me:I've split this into three build steps. The first one builds python from src, the second one builds the go program against our custom python and the third one is for running the compiled Go program (a more minimal container with no build tools installed and both our go program and our custom python in
/opt). You could of course also all do it in one container or machine.To try:
YangChuanMakeSense commentedon Mar 15, 2021
@christian-korneck thank you very much,
--enable-sharedhelps a lot.floki2020 commentedon May 17, 2021
hi @christian-korneck ,i had the same problem ,and i used pyenv to install the python3.7 with options configure --enable-shared.but it still doesnt work. i can't use docker. thanks for your help~
os:ubuntu 20.04
christian-korneck commentedon Aug 5, 2021
@floki2020 this works for me on Ubuntu 20.04:
and you should see output
(sorry if it's a bit clunky, copied from an ssh client on my phone. But hopefully it should get you an idea how to get it to work?)