TypeError: 不能直接创建描述符

我试图安装 ,但它出现了一个错误:

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

我试图解决这个问题,并降低了 普罗布福的评级:

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

但问题仍然存在于 Ray、 张量流克拉斯中。我的申请已经不起作用了。我该怎么补救?

98454 次浏览

I found the same problem, but I followed the instructions on this web page:

Python Packaging User Guide (on GitHub)

Steps

Requirements / prerequisites:

  1. sphinx 4.3.1

  2. sphinx-autobuild 0.7.1

  3. sphinx-inline-tabs 2021.4.11b9

  4. python-docs-theme 2021.5

  5. sphinx-copybutton 0.4.0

  6. Output of python -V:

    Python 3.8.10

  7. Output of protoc.exe --version:

    libprotoc 3.21.0-rc2

Installation:

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

  2. Compile libraries

  3. Copy the compiled 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

In my case I did not have protobuf explicitly in my requirements.txt file, 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.

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:

Alternatively, I was able to upgrade to wandb==0.12.17, and everything seems to be working.

Old (not working):

  - pip:
- wandb==0.10.21

New (working):

  - pip:
- wandb==0.12.17

Descriptors cannot not be created directly:

  1. We need to downgrade the protobuf package from 4.21.2 to 3.20.1.
  2. Go to setting → ProjectPython Interpreter → install protobuf 3.20.1 (specify version)

Solution 1: Downgrade protobuf protobuf has recently Released the latest version and the Cause of this Update This error Occurs. All We Need to do is just Downgrade protobuf to 3.20.1 and Your error will be solved. To Downgrade protobuf Just Run This command in your terminal.

pip install --upgrade "protobuf<=3.20.1"

Or You can Use Force

pip install 'protobuf<=3.20.1' --force-reinstall

And Now, Your error must be solved Thanks.

Solution 2: Update TensorFlow to the Latest version TensorFlow has Released the Latest version 2.9.1 On 23 May 2022 Just Update its Latest version and May Your error will be solved. You can use This Command.

pip install tensorflow==2.9.1

Always use latest version of tensorflow

First time show some error then try again. I wish problem will be solved.

Even I came across same error

I solved it by installing protobuf

pip install protobuf==3.20.*

Screen Snippet

I had the same issue after upgrading google cloud logging. I solved it upgrading google-cloud-audit-log.

pip install google-cloud-audit-log==0.2.4

Working versions:

pip freeze | grep google


google-api-core==2.10.2
google-api-python-client==2.57.0
google-auth==2.10.0
google-auth-httplib2==0.1.0
google-auth-oauthlib==0.5.2
google-cloud-appengine-logging==1.1.6
google-cloud-audit-log==0.2.4
google-cloud-core==2.3.2
google-cloud-logging==3.2.5
google-cloud-storage==2.5.0
google-crc32c==1.1.2
google-resumable-media==2.4.0
googleapis-common-protos==1.56.4
grpc-google-iam-v1==0.12.4

I hope this helps. Cheers