Skip to content
This repository has been archived by the owner on Aug 10, 2022. It is now read-only.

can this work on windows ? #24

Open
BenDerPan opened this issue Jan 2, 2020 · 6 comments
Open

can this work on windows ? #24

BenDerPan opened this issue Jan 2, 2020 · 6 comments

Comments

@BenDerPan
Copy link

Describe what happened:
I try to use mingw64 to install go-python3 on windows, but failed:

go get -u -v github.com/DataDog/go-python3
github.com/DataDog/go-python3 (download)
github.com/DataDog/go-python3
# pkg-config --cflags  -- python3
Package python3 was not found in the pkg-config search path.
Perhaps you should add the directory containing `python3.pc'
to the PKG_CONFIG_PATH environment variable
No package 'python3' found
pkg-config: exit status 1

the PKG_CONFIG_PATH environment variable is already set to my python3.exe directory.

Describe what you expected:

Steps to reproduce the issue:

@hush-hush
Copy link
Member

Hi @BenDerPan,

The bindings should work on Windows (I haven't tried), nothing is Linux specific.
Are you sure your setup for pkg-config is working ? Does this command works on you build environment pkg-config --cflags python3 ?

@MarSoft
Copy link

MarSoft commented Mar 27, 2020

There is a problem though.

Probably we can somehow build some parts using MSVC and other parts using migw32-w64, but I am not sure how can this be achieved.

In fact, the issue I bumped into when first tried to build with mingw-w64: Python.h header requires crypt.h, which is missing in mingw headers.

There is a mingwpy project there which aims to support building python modules with mingw, but it is seemingly dead and doesn't mention any support for python>3.5.

@Zalberth
Copy link

Same issure on MacOS by using go get -u github.com/DataDog/go-python3. Python3 already installed by pkg.

@christian-korneck
Copy link
Contributor

christian-korneck commented Aug 9, 2020

first of all thanks a lot for this great project 🙏

can this work on windows

this go module works fine for me so far on Windows 10. However, I don't use mingw. This is what I do for Python 3.7 x64:

  • go to the Python 3.7.7 downloads page and download the Windows x86-64 embeddable zip file (direct link) and extract it to i.e. c:\dist (this will become the build output dir for your app and you will need to bundle these files with your app)
  • obtain the include dir from a regular Python 3.7.7 x64 installation (direct link regular installer) and put it somewhere (i.e. to c:\py\include)
  • install TDM GCC (i.e. to c:\tdm-gcc)
  • install pkgconfig (easiest way I find is with the chocolatey package manager: choco install pkgconfiglite)
  • in your project, create a pkg-config\python3.pc file with these paths
prefix=C:/dist
exec_prefix=${prefix}
libdir=${exec_prefix}
includedir=C:/py/include

Name: Python
Description: Python library embedded
Requires:
Version: 3.7
Libs: -L${libdir} -lpython37 -lpthread -lm
Cflags: -I${includedir} -DMS_WIN64

in a cmd shell navigate to your project root and set the environment:

set PATH=c:\dist;c:\tdm-gcc\bin;%PATH%
set PKG_CONFIG_PATH=%cd%\pkg-config

now we can build our app:

go build -o c:\dist

and run it (should work from any shell, i.e. the above env vars don't need to be set for running):

c:\dist\myapp.exe

One more note: If you accidentally compile against the wrong Python binaries the go build cache can be "dirty" (happened to me a couple of times). In that case rename/delete the folder that go env GOCACHE shows.

@equisde
Copy link

equisde commented Jul 23, 2021

first of all thanks a lot for this great project 🙏

can this work on windows

this go module works fine for me so far on Windows 10. However, I don't use mingw. This is what I do for Python 3.7 x64:

  • go to the Python 3.7.7 downloads page and download the Windows x86-64 embeddable zip file (direct link) and extract it to i.e. c:\dist (this will become the build output dir for your app and you will need to bundle these files with your app)
  • obtain the include dir from a regular Python 3.7.7 x64 installation (direct link regular installer) and put it somewhere (i.e. to c:\py\include)
  • install TDM GCC (i.e. to c:\tdm-gcc)
  • install pkgconfig (easiest way I find is with the chocolatey package manager: choco install pkgconfiglite)
  • in your project, create a pkg-config\python3.pc file with these paths
prefix=C:/dist
exec_prefix=${prefix}
libdir=${exec_prefix}
includedir=C:/py/include

Name: Python
Description: Python library embedded
Requires:
Version: 3.7
Libs: -L${libdir} -lpython37 -lpthread -lm
Cflags: -I${includedir} -DMS_WIN64

in a cmd shell navigate to your project root and set the environment:

set PATH=c:\dist;c:\tdm-gcc\bin;%PATH%
set PKG_CONFIG_PATH=%cd%\pkg-config

now we can build our app:

go build -o c:\dist

and run it (should work from any shell, i.e. the above env vars don't need to be set for running):

c:\dist\myapp.exe

One more note: If you accidentally compile against the wrong Python binaries the go build cache can be "dirty" (happened to me a couple of times). In that case rename/delete the folder that go env GOCACHE shows.

hello i'm new to golang i tried to use your instruction i was able to go get the package and compile but when running i get this

Exception 0xc0000005 0x0 0x10 0x7ffe1214f90d
PC=0x7ffe1214f90d

runtime: unknown pc 0x7ffe1214f90d
stack: frame={sp:0xdcd63ffaa0, fp:0x0} stack=[0x0,0xdcd63ffbe0)
000000dcd63ff9a0:  0000000000000008  00007ffe121691bb
000000dcd63ff9b0:  0000024540f90030  00007ffe1230a238
000000dcd63ff9c0:  0000000000000000  0000000000000000
000000dcd63ff9d0:  0000000000000004  0000000000000000
000000dcd63ff9e0:  0000000000000010  0000000000000000
000000dcd63ff9f0:  0000000000000001  0000000000000000
000000dcd63ffa00:  000002451bb20000  00007ffe6a7090cc
000000dcd63ffa10:  0000000000000000  0000024540f90060
000000dcd63ffa20:  0000007f00000001  0000000000000008
000000dcd63ffa30:  0000000000000008  0000000000000008
000000dcd63ffa40:  000000000000007f  0000000000000000
000000dcd63ffa50:  0000000000000000  00007ffe1230a240
000000dcd63ffa60:  00007ffe68ad0000  0000000000000000
000000dcd63ffa70:  000000000000000b  0000000000000001
000000dcd63ffa80:  0000000000000000  000002451bb26cf0
000000dcd63ffa90:  0000000000000000  ffffffffffffffff
000000dcd63ffaa0: <0000000000000025  00007ff7cc9174b8
000000dcd63ffab0:  00007ff7cc8fb920  00007ff7cc9911e0
000000dcd63ffac0:  0000024540f90030  00007ffe12189fd0
000000dcd63ffad0:  00007ffe1230a240  00007ffe1230a238
000000dcd63ffae0:  0000000000000000  0000000000000000
000000dcd63ffaf0:  000002451bb26cf0  00007ffe12175710
000000dcd63ffb00:  0000000000000000  00007ffe68c0c750
000000dcd63ffb10:  0000000000000000  0000000000000004
000000dcd63ffb20:  0000024540f518b8  0000000000000000
000000dcd63ffb30:  000000c000110000  00007ff7cc8c5caf
000000dcd63ffb40:  000000c00010ff20  0000000000000004
000000dcd63ffb50:  00007ff7cc86e4cd <runtime.wakep+109>  0000024540f518c8
000000dcd63ffb60:  000000c00010ff20  00007ff7cc9911e0
000000dcd63ffb70:  000000c00010ff20  00007ff7cc896753 <runtime.asmcgocall+115>
000000dcd63ffb80:  00007ff7cc9174f8  0000000000000010
000000dcd63ffb90:  00007ff7cc8f9b80  00007ff7cc8f9b80
runtime: unknown pc 0x7ffe1214f90d
stack: frame={sp:0xdcd63ffaa0, fp:0x0} stack=[0x0,0xdcd63ffbe0)
000000dcd63ff9a0:  0000000000000008  00007ffe121691bb
000000dcd63ff9b0:  0000024540f90030  00007ffe1230a238
000000dcd63ff9c0:  0000000000000000  0000000000000000
000000dcd63ff9d0:  0000000000000004  0000000000000000
000000dcd63ff9e0:  0000000000000010  0000000000000000
000000dcd63ff9f0:  0000000000000001  0000000000000000
000000dcd63ffa00:  000002451bb20000  00007ffe6a7090cc
000000dcd63ffa10:  0000000000000000  0000024540f90060
000000dcd63ffa20:  0000007f00000001  0000000000000008
000000dcd63ffa30:  0000000000000008  0000000000000008
000000dcd63ffa40:  000000000000007f  0000000000000000
000000dcd63ffa50:  0000000000000000  00007ffe1230a240
000000dcd63ffa60:  00007ffe68ad0000  0000000000000000
000000dcd63ffa70:  000000000000000b  0000000000000001
000000dcd63ffa80:  0000000000000000  000002451bb26cf0
000000dcd63ffa90:  0000000000000000  ffffffffffffffff
000000dcd63ffaa0: <0000000000000025  00007ff7cc9174b8
000000dcd63ffab0:  00007ff7cc8fb920  00007ff7cc9911e0
000000dcd63ffac0:  0000024540f90030  00007ffe12189fd0
000000dcd63ffad0:  00007ffe1230a240  00007ffe1230a238
000000dcd63ffae0:  0000000000000000  0000000000000000
000000dcd63ffaf0:  000002451bb26cf0  00007ffe12175710
000000dcd63ffb00:  0000000000000000  00007ffe68c0c750
000000dcd63ffb10:  0000000000000000  0000000000000004
000000dcd63ffb20:  0000024540f518b8  0000000000000000
000000dcd63ffb30:  000000c000110000  00007ff7cc8c5caf
000000dcd63ffb40:  000000c00010ff20  0000000000000004
000000dcd63ffb50:  00007ff7cc86e4cd <runtime.wakep+109>  0000024540f518c8
000000dcd63ffb60:  000000c00010ff20  00007ff7cc9911e0
000000dcd63ffb70:  000000c00010ff20  00007ff7cc896753 <runtime.asmcgocall+115>
000000dcd63ffb80:  00007ff7cc9174f8  0000000000000010
000000dcd63ffb90:  00007ff7cc8f9b80  00007ff7cc8f9b80

goroutine 1 [syscall]:
github.com/DataDog/go-python3._Cfunc_PyRun_SimpleStringFlags(0x2451bb26cf0, 0x0, 0x24500000000)
        _cgo_gotypes.go:4695 +0x4b
github.com/DataDog/go-python3.PyRun_SimpleString(0x7ff7cc90e71e, 0x3, 0x0)
        C:/Users/rbert/go/pkg/mod/github.com/!data!dog/go-python3@v0.0.0-20191126174558-6ed25e33b3c4/high_level_layer.go:66 +0x93
main.main()
        D:/!-criss/main.go:9 +0x3d
rax     0x0
rbx     0x24540f90030
rcx     0xdcd63ffa10
rdi     0x2451bb26cf0
rsi     0x7ff7cc9911e0
rbp     0xc00010fee0
rsp     0xdcd63ffaa0
r8      0x24540f90060
r9      0x24540f90000
r10     0xfc0
r11     0x246
r12     0x7ff7cc8fb920
r13     0x7ff7cc9174b8
r14     0x25
r15     0xffffffffffffffff
rip     0x7ffe1214f90d
rflags  0x10206
cs      0x33
fs      0x53
gs      0x2b

@christian-korneck
Copy link
Contributor

christian-korneck commented Sep 6, 2021

i was able to go get the package and compile but when running i get this

@equisde I don't know what's the problem you're seeing, but I've just created a quick github actions demo project that builds a simple Windows executable with go-python3. If you like you can fork it, run it on your github account and compare it with your setup. Hope this helps.

Sign up for free to subscribe to this conversation on GitHub. Already have an account? Sign in.
Labels
None yet
Projects
None yet
Development

No branches or pull requests

6 participants