Home > Software design >  TypeError: Descriptors cannot not be created directly
TypeError: Descriptors cannot not be created directly

Time:06-03

I tried to install ray but it gave error

TypeError: Descriptors cannot not be created directly.
If this call came from a _pb2.py file, your generated code is out of date and must be regenerated with protoc >= 3.19.0.
If you cannot immediately regenerate your protos, some other possible workarounds are:
 1. Downgrade the protobuf package to 3.20.x or lower.
 2. Set PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python (but this will use pure-Python parsing and will be much slower).

I tried to solve the problem and downgraded protobuf

Name: protobuf
Version: 3.20.0
Summary: Protocol Buffers
Home-page: https://developers.google.com/protocol-buffers/
Author:
Author-email:
License: BSD-3-Clause
Location: d:\opencv\lib\site-packages
Requires:
Required-by: ray, tensorboard, tensorflow

but still problem persists in ray, tf and keras, my application isn't working any more. help:(

CodePudding user response:

I found the same problem but I follow the instructions on the websites:

https://packaging.python.org/en/latest/

https://github.com/pypa/packaging.python.org

[ Steps ]:

[ Requirements ]:
sphinx==4.3.1
sphinx-autobuild==0.7.1
sphinx-inline-tabs==2021.4.11b9
python-docs-theme==2021.5
sphinx-copybutton==0.4.0

1. python -V
Python 3.8.10

2. protoc.exe --version 
libprotoc 3.21.0-rc2

3. pip install git https://github.com/pypa/pypa-docs-theme.git#egg=pypa-docs-theme

4. complie libraries

5. copy complied library from F:\temp\Python\protoc\packaging.python.org\protobuf\Debug to F:\temp\Python\protoc\packaging.python.org\protobuf\src 

[ Output ]:

installing library code to build\bdist.win-amd64\egg
running install_lib
running build_py
creating build\lib.win-amd64-3.8
creating build\lib.win-amd64-3.8\google
copying google\__init__.py -> build\lib.win-amd64-3.8\google
creating build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\any_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\api_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\descriptor.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\descriptor_database.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\descriptor_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\descriptor_pool.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\duration_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\empty_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\field_mask_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\json_format.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\message.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\message_factory.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\proto_builder.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\reflection.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\service.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\service_reflection.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\source_context_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\struct_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\symbol_database.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\text_encoding.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\text_format.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\timestamp_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\type_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\unknown_fields.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\wrappers_pb2.py -> build\lib.win-amd64-3.8\google\protobuf
copying google\protobuf\__init__.py -> build\lib.win-amd64-3.8\google\protobuf

...
testTimestampSerializeAndParse (google.protobuf.internal.well_known_types_test.TimeUtilTest) ... ok
testTimezoneAwareDatetimeConversionLA (google.protobuf.internal.well_known_types_test.TimeUtilTest)
testTimezoneAwareDatetimeConversionLA([1969, 12, 31, 18], datetime.timezone(datetime.timedelta(days=-1, seconds=57600), 'US/Pacific')) ... ok
testTimezoneAwareDatetimeConversionLondon (google.protobuf.internal.well_known_types_test.TimeUtilTest)
testTimezoneAwareDatetimeConversionLondon([1970, 1, 1, 2], datetime.timezone.utc) ... ok
testTimezoneAwareDatetimeConversionTokyo (google.protobuf.internal.well_known_types_test.TimeUtilTest)
testTimezoneAwareDatetimeConversionTokyo([1970, 1, 1, 11], datetime.timezone(datetime.timedelta(seconds=32400), 'Japan')) ... ok
testTimezoneNaiveDatetimeConversion (google.protobuf.internal.well_known_types_test.TimeUtilTest) ... ok
testByteSizeFunctions (google.protobuf.internal.wire_format_test.WireFormatTest) ... ok
testPackTag (google.protobuf.internal.wire_format_test.WireFormatTest) ... ok
testUnpackTag (google.protobuf.internal.wire_format_test.WireFormatTest) ... ok
testZigZagDecode (google.protobuf.internal.wire_format_test.WireFormatTest) ... ok
testZigZagEncode (google.protobuf.internal.wire_format_test.WireFormatTest) ... ok

CodePudding user response:

In my case I did not have protobuf explicitly in my requirements.txt but I did have a related dependency which was apparently problematic:

googleapis-common-protos==1.6.0 # depends on protobuf

REMOVING this allowed the subsequent pip install -e . (assuming setup.py is present) to go with whatever google-api-core==1.13.0 had for dependencies. That resulted in the installation of googleapis-common-protos==1.56.2 and resolved the error.

  • Related