【问题标题】:TypeError: Descriptors cannot not be created directlyTypeError:不能直接创建描述符
【发布时间】:2022-06-15 18:26:44
【问题描述】:

我尝试安装 ray 但报错

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

我试图解决问题并降级了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

但是 ray、tf 和 keras 中仍然存在问题,我的应用程序不再工作。求助:(

【问题讨论】:

标签: python tensorflow ray


【解决方案1】:

有时protobuf 软件包可能会在您不参与的情况下安装。为此,您有两种解决方案可供应用。尝试以下解决方案之一,它应该可以工作。

解决方案 01:-

你可以降级protobuf插件,

pip install protobuf==3.20.*

或者您可以将它作为最后一个包添加到requirements.txt 文件中。因为这会覆盖之前安装的protobuf 包。

...
protobuf==3.20.*

解决方案 02:-

您可以设置以下环境变量。

export PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python

根据错误描述,这可能会影响您的程序性能。

但这将使用纯 Python 解析并且会慢得多


参考:-

【讨论】:

  • 在遵循解决方案 01 和解决方案 02 之后,都导致我的程序运行速度慢了约 5 倍。我还尝试重建环境,但它仍然运行缓慢。我的猜测是,即使使用解决方案 01,也有一些东西在强制 PROTOCOL_BUFFERS_PYTHON_IMPLEMENTATION=python,但我无法检查它。它发生在其他人身上吗?怎样才能回到原来的状态?
  • 你是对的@Guillem,解决方案 02 可能会影响你的程序性能,他们也在错误描述中提到了它。但是解决方案 01 应该可以工作
【解决方案2】:

我发现了同样的问题,但我按照网站上的说明进行操作:

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

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

[步骤]:

[ 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 

[输出]:

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

【讨论】:

    【解决方案3】:

    在我的情况下,我的requirements.txt 中没有明确的protobuf,但我确实有一个相关的依赖关系,这显然是有问题的:

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

    删除它允许随后的pip install -e .(假设存在setup.py)与google-api-core==1.13.0 的任何依赖项一起使用。这导致安装了googleapis-common-protos==1.56.2 并解决了错误。

    【讨论】:

      【解决方案4】:

      或者,我能够升级到wandb==0.12.17,一切似乎都正常。

      旧的(不工作):

        - pip:
            - wandb==0.10.21
      

      新的(工作):

        - pip:
            - wandb==0.12.17
      

      【讨论】:

        猜你喜欢
        • 2022-06-11
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        • 2012-03-27
        • 1970-01-01
        • 1970-01-01
        • 1970-01-01
        相关资源
        最近更新 更多