protobuf icon indicating copy to clipboard operation
protobuf copied to clipboard

Python3.11: external/com_google_protobuf/python/message.c:160: PyUpb_CPythonBits_Init: Assertion `bits->type_basicsize == sizeof(PyHeapTypeObject)' failed.`

Open CherryLiu8023 opened this issue 6 months ago • 9 comments

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?

  1. 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

CherryLiu8023 avatar Jun 19 '25 07:06 CherryLiu8023

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

CherryLiu8023 avatar Jun 19 '25 09:06 CherryLiu8023

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.

xhochy avatar Jul 01 '25 09:07 xhochy

I will give it a try, thanks~

CherryLiu8023 avatar Jul 01 '25 10:07 CherryLiu8023

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

h-vetinari avatar Jul 04 '25 22:07 h-vetinari

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.

jguamie avatar Sep 16 '25 17:09 jguamie

This happened on OSX and Linux, for Python 3.11 for me.

xhochy avatar Sep 18 '25 13:09 xhochy

What are you trying to do here? Can you please provide more context on what you're trying to implement or do?

jguamie avatar Sep 22 '25 05:09 jguamie

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).

h-vetinari avatar Sep 22 '25 09:09 h-vetinari

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.

bellspice avatar Oct 28 '25 17:10 bellspice