cpy3 icon indicating copy to clipboard operation
cpy3 copied to clipboard

repo example codes failed to run

Open eliranwong opened this issue 2 years ago • 3 comments


Note: If you have a usage question (i.e. how to achieve something specific using this library + the CPython C-API) consider posting it to this project's GitHub Discussions board instead of creating an issue. Any question is welcome!


Describe what happened:

your examples code failed to run:

github.com/go-python/cpy3

../../dict.go:141:13: could not determine kind of name for C.PyDict_ClearFreeList

github.com/go-python/cpy3

../../dict.go:141:13: could not determine kind of name for C.PyDict_ClearFreeList

Describe what you expected:

I expect your examples work

Steps to reproduce the issue:

git clone https://github.com/go-python/cpy3.git

cd cpy3/examples/list/

go run main.go

cd ../python3/

go run main.go

eliranwong avatar Jan 07 '23 20:01 eliranwong

@eliranwong what Python version are you using? This library currently only works with Python 3.7. This error usually happens when trying to use a newer version of Python.

The C.PyDict_ClearFreeList function has been removed from the Python C API with Python 3.9.

It is possible to use newer version of Python if you remove some functions from go-python/cpy3 / datadog/go-python3 (bindings to stuff that has been removed from Python's C-API in newer version). For example, Python 3.8 works if you remove the bindings for PyEval_ReInitThreads, like I did here. More stuff might need to get removed for Python 3.9 and newer.

If you're having trouble installing Python 3.7 on your Linux distro, we have various examples of how to build it from source:

  • Docker/Debian (Ubuntu is very similar): https://github.com/go-python/cpy3/discussions/18
  • Fedora (RHEL/CentOS/Rocky/Alma is very similar): https://github.com/go-python/cpy3/discussions/17
  • Ubuntu 20.04 (install from deadsnakes apt repo): https://github.com/go-python/cpy3/issues/29#issuecomment-1321246701

Hope this helps.

christian-korneck avatar Jan 07 '23 21:01 christian-korneck

oic, I am using python 3.9.2 that comes with Debian 11

eliranwong avatar Jan 07 '23 21:01 eliranwong

@eliranwong try https://github.com/soulteary/docker-python-in-go/

soulteary avatar May 21 '23 16:05 soulteary