Python3.11: external/com_google_protobuf/python/message.c:160: PyUpb_CPythonBits_Init: Assertion `bits->type_basicsize == sizeof(PyHeapTypeObject)' failed.`
This is the core error when running some onnx related libs api in python3.11 env.
What version of protobuf and what language are you using? 4.25.0 with some local patches
What operating system (Linux, Windows, ...) and version? Linux
What runtime / compiler are you using (e.g., python version or gcc version) python3.11
What did you do?
- add patch to our repo python/BUILD file to change the python_version build_setting_default -> 311 , does not work
What did you expect to see 2. it works for some onnx related libs to work on pythoin3.11, for example, onnxsim ../ndas/onnx.model ./sim_onnx.model. That's all relies on protobuf
What did you see instead?
Make sure you include information that can help us debug (full error message, exception listing, stack trace, logs). other python3.11 related issue and replies do not help to solve this issue
Anything else we should know about your project / environment
After setting the system_python to python3.11, we met another error of platform incompatible issue
system_python(
name = "system_python",
minimum_python_version = "3.11",
)
@com_google_protobuf//python:_message_binary (67b96d) <-- target platform (//bazel/platforms:host_linux_6_0_9) didn't satisfy constraint @platforms//:incompatible
This seems to depend on the SUPPORTED_PYTHON_VERSIONS[-1] used in MODULE.bazel. If I set that to exactly the current Python versions, the error vanishes.
I will give it a try, thanks~
The logic of using SUPPORTED_PYTHON_VERSIONS[-1] to determine which version is the "default" is obviously a bit fragile
https://github.com/protocolbuffers/protobuf/blob/960e79087b332583c80537c949621108a85aa442/MODULE.bazel#L136-L144
We need more information on what architecture you are using and what you are trying to do here. Also, we are in the middle of cleaning up system_python.
This happened on OSX and Linux, for Python 3.11 for me.
What are you trying to do here? Can you please provide more context on what you're trying to implement or do?
What are you trying to do here?
Build protobuf from source for a specific python version as "system python", which should really not require patching, but because of the hard-coded logic in MODULE.bazel involving SUPPORTED_PYTHON_VERSIONS[-1], this doesn't work.
Some more context: @xhochy and myself are involved in distributing protobuf (and 1000s of other packages) in the conda-forge ecosystem. We tend to know what we're doing (and happy to explain how/why).
Bzlmod was not supported in 4.25, and 4.25 is no longer a supported version of Python Protobuf. Additionally, Python-upb is not supported in Bazel. We recommend using more modern/supported versions. If you can reproduce from pypy, please reopen (or open a new issue) and we'll look into it.