Closed trueToastedCode closed 1 year ago
It works for me when using the macOS bundled Python (/usr/local/bin/python3
), but fails when attempting to use one provisioned by Conda.
$ gopy build -output=out -vm=python3 github.com/go-python/gopy/_examples/hi
--- Processing package: github.com/go-python/gopy/_examples/hi ---
--- building package ---
gopy build -output=out -vm=python3 github.com/go-python/gopy/_examples/hi
goimports -w hi.go
go build -mod=mod -buildmode=c-shared -o hi_go.so .
/Users/tshiri/miniconda3/envs/py38/bin/python3 build.py
CGO_CFLAGS=-I/Users/tshiri/miniconda3/envs/py38/include/python3.8 -fPIC -Ofast
CGO_LDFLAGS=-L/Users/tshiri/miniconda3/envs/py38/lib -lpython3.8 -ldl -framework CoreFoundation
go build -mod=mod -buildmode=c-shared -o _hi.cpython-38-darwin.so .
$ which python
/Users/tshiri/miniconda3/envs/py38/bin/python
$ python
>>> import out.hi
Fatal Python error: _PyInterpreterState_Get(): no current thread state
Python runtime state: unknown
Process 58564 stopped
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
frame #0: 0x00000001a0e2ed98 libsystem_kernel.dylib`__pthread_kill + 8
libsystem_kernel.dylib`:
-> 0x1a0e2ed98 <+8>: b.lo 0x1a0e2edb8 ; <+40>
0x1a0e2ed9c <+12>: pacibsp
0x1a0e2eda0 <+16>: stp x29, x30, [sp, #-0x10]!
0x1a0e2eda4 <+20>: mov x29, sp
Target 1: (python) stopped.
(lldb) bt
* thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT
* frame #0: 0x00000001a0e2ed98 libsystem_kernel.dylib`__pthread_kill + 8
frame #1: 0x00000001a0e63ee0 libsystem_pthread.dylib`pthread_kill + 288
frame #2: 0x00000001a0d9e340 libsystem_c.dylib`abort + 168
frame #3: 0x0000000105127028 libpython3.8.dylib`fatal_error + 684
frame #4: 0x00000001051271a4 libpython3.8.dylib`Py_FatalError + 24
frame #5: 0x000000010504a670 libpython3.8.dylib`PyModule_Create2 + 56
frame #6: 0x000000010013ee4c python`_PyImport_LoadDynamicModuleWithSpec + 1276
frame #7: 0x000000010013dd24 python`_imp_create_dynamic + 456
frame #8: 0x00000001000755f0 python`cfunction_vectorcall_FASTCALL + 284
frame #9: 0x0000000100028008 python`PyVectorcall_Call + 120
frame #10: 0x0000000100110ce4 python`_PyEval_EvalFrameDefault + 28320
frame #11: 0x000000010010982c python`_PyEval_EvalCodeWithName + 3008
frame #12: 0x0000000100028948 python`_PyFunction_Vectorcall + 208
It works for me when using the macOS bundled Python (
/usr/local/bin/python3
), but fails when attempting to use one provisioned by Conda.$ gopy build -output=out -vm=python3 github.com/go-python/gopy/_examples/hi --- Processing package: github.com/go-python/gopy/_examples/hi --- --- building package --- gopy build -output=out -vm=python3 github.com/go-python/gopy/_examples/hi goimports -w hi.go go build -mod=mod -buildmode=c-shared -o hi_go.so . /Users/tshiri/miniconda3/envs/py38/bin/python3 build.py CGO_CFLAGS=-I/Users/tshiri/miniconda3/envs/py38/include/python3.8 -fPIC -Ofast CGO_LDFLAGS=-L/Users/tshiri/miniconda3/envs/py38/lib -lpython3.8 -ldl -framework CoreFoundation go build -mod=mod -buildmode=c-shared -o _hi.cpython-38-darwin.so .
$ which python /Users/tshiri/miniconda3/envs/py38/bin/python $ python >>> import out.hi Fatal Python error: _PyInterpreterState_Get(): no current thread state Python runtime state: unknown Process 58564 stopped * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT frame #0: 0x00000001a0e2ed98 libsystem_kernel.dylib`__pthread_kill + 8 libsystem_kernel.dylib`: -> 0x1a0e2ed98 <+8>: b.lo 0x1a0e2edb8 ; <+40> 0x1a0e2ed9c <+12>: pacibsp 0x1a0e2eda0 <+16>: stp x29, x30, [sp, #-0x10]! 0x1a0e2eda4 <+20>: mov x29, sp Target 1: (python) stopped. (lldb) bt * thread #1, queue = 'com.apple.main-thread', stop reason = signal SIGABRT * frame #0: 0x00000001a0e2ed98 libsystem_kernel.dylib`__pthread_kill + 8 frame #1: 0x00000001a0e63ee0 libsystem_pthread.dylib`pthread_kill + 288 frame #2: 0x00000001a0d9e340 libsystem_c.dylib`abort + 168 frame #3: 0x0000000105127028 libpython3.8.dylib`fatal_error + 684 frame #4: 0x00000001051271a4 libpython3.8.dylib`Py_FatalError + 24 frame #5: 0x000000010504a670 libpython3.8.dylib`PyModule_Create2 + 56 frame #6: 0x000000010013ee4c python`_PyImport_LoadDynamicModuleWithSpec + 1276 frame #7: 0x000000010013dd24 python`_imp_create_dynamic + 456 frame #8: 0x00000001000755f0 python`cfunction_vectorcall_FASTCALL + 284 frame #9: 0x0000000100028008 python`PyVectorcall_Call + 120 frame #10: 0x0000000100110ce4 python`_PyEval_EvalFrameDefault + 28320 frame #11: 0x000000010010982c python`_PyEval_EvalCodeWithName + 3008 frame #12: 0x0000000100028948 python`_PyFunction_Vectorcall + 208
Ok thx... succeeded to import using the Python from Homebrew
$ which python3
/opt/homebrew/bin/python3
But now there is the next problem:
>>> import out.hi
>>> dir(hi)
['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__spec__', '_collections_abc', '_hi', 'collections', 'currentdir', 'cwd', 'go', 'inspect', 'os', 'sys']
the package doesn't include any of the defined methods from hi.go... e.g. Hi
out.hi.Hi()
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
AttributeError: module 'out.hi' has no attribute 'Hi'
also tried to make my own go module... same result... methods defined in go, won't be available in python :(
MOVED THIS TO: https://github.com/go-python/gopy/issues/315
Was following the Examples from README
It compiles... however the import doesn't work