TypeError: Descriptors cannot not be created directly

Sometimes the protobuf package might be installed without your involvement. For this, you have two solutions to apply. Try one of the below solutions and it should work.

Solution 1:

You can downgrade the protobuf plugin,

pip install protobuf==3.20.*

Or you can add it to the requirements.txt file as the last package. Because this will override the previously installed protobuf package.

...
protobuf==3.20.*

Solution 2:

You can set the following environment variable.

export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

according to the error description, this might impact your program performance.

but this will use pure-Python parsing and will be much slower


References:

Leave a Comment