“TypeError:无法使用 google-cloud-compute 将原型文件构建到描述符池中”

问题描述 投票:0回答:1

我正在 Ubuntu 22 上使用 Python 3.13.0 运行 Python 应用程序。

自从从 3.12 升级 Python 以来,运行应用程序时出现此错误:

TypeError: Couldn't build proto file into descriptor pool: duplicate symbol 'google.cloud.compute.v1.AccessConfig.__firstlineno__'

该应用程序是开源的,位于:https://github.com/VerinFast/verinfast

requirements.txt中的相关项目:

google-cloud-compute>=1.14.0

protobuf 不在requirements.txt 中,但必须由另一个包安装。

该错误是由导入 google-cloud-compute 触发的:

from google.cloud import compute_v1

所以我创建了一个名为 test.py 的单行文件:

from google.cloud import compute_v1

如果我运行它:

python test.py

我得到同样长的错误:

/usr/lib/python3/dist-packages/requests/__init__.py:87: RequestsDependencyWarning: urllib3 (2.2.3) or chardet (5.2.0) doesn't match a supported version!
  warnings.warn("urllib3 ({}) or chardet ({}) doesn't match a supported "
Traceback (most recent call last):
  File "/home/stconrad/proto_error/test.py", line 1, in <module>
    from google.cloud import compute_v1
  File "/home/stconrad/.local/lib/python3.13/site-packages/google/cloud/compute_v1/__init__.py", line 21, in <module>
    from .services.accelerator_types import AcceleratorTypesClient
  File "/home/stconrad/.local/lib/python3.13/site-packages/google/cloud/compute_v1/services/accelerator_types/__init__.py", line 16, in <module>
    from .client import AcceleratorTypesClient
  File "/home/stconrad/.local/lib/python3.13/site-packages/google/cloud/compute_v1/services/accelerator_types/client.py", line 51, in <module>
    from google.cloud.compute_v1.services.accelerator_types import pagers
  File "/home/stconrad/.local/lib/python3.13/site-packages/google/cloud/compute_v1/services/accelerator_types/pagers.py", line 41, in <module>
    from google.cloud.compute_v1.types import compute
  File "/home/stconrad/.local/lib/python3.13/site-packages/google/cloud/compute_v1/types/__init__.py", line 16, in <module>
    from .compute import (
    ...<1496 lines>...
    )
  File "/home/stconrad/.local/lib/python3.13/site-packages/google/cloud/compute_v1/types/compute.py", line 111135, in <module>
    class ZoneSetPolicyRequest(proto.Message):
    ...<40 lines>...
        )
  File "/home/stconrad/.local/lib/python3.13/site-packages/proto/message.py", line 279, in __new__
    file_info.generate_file_pb(new_class=cls, fallback_salt=full_name)
    ~~~~~~~~~~~~~~~~~~~~~~~~~~^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^
  File "/home/stconrad/.local/lib/python3.13/site-packages/proto/_file_info.py", line 104, in generate_file_pb
    pool.Add(self.descriptor)
    ~~~~~~~~^^^^^^^^^^^^^^^^^
TypeError: C

来自 pip show protobuf:

Name: protobuf
Version: 5.28.2
Summary:
Home-page: https://developers.google.com/protocol-buffers/
Author: [email protected]
Author-email: [email protected]
License: 3-Clause BSD License
Location: /home/stconrad/.local/lib/python3.13/site-packages
Requires:
Required-by: google-api-core, google-cloud-compute, google-cloud-monitoring, googleapis-common-protos, grpcio-status, opentelemetry-proto, proto-plus

并且 pip 显示 google-cloud-compute:

Name: google-cloud-compute
Version: 1.19.2
Summary: Google Cloud Compute API client library
Home-page: https://github.com/googleapis/google-cloud-python/tree/main/packages/google-cloud-compute
Author: Google LLC
Author-email: [email protected]
License: Apache 2.0
Location: /home/stconrad/.local/lib/python3.13/site-packages
Requires: google-api-core, google-auth, proto-plus, protobuf
Required-by: verinfast

看起来 google-cloud-compute 或 protobuf 对于 Python 3.13 来说已经损坏了,这是不幸的,因为它是 10 月 7 日发布的。

寻找解决方法。

我尝试包装导入:

try:
    from google.api_core.exceptions import NotFound
    from google.cloud import compute_v1
    from google.cloud.monitoring_v3 import Aggregation, MetricServiceClient, TimeInterval, ListTimeSeriesRequest  # noqa: E501
except:
    print("Google Cloud libraries not imported. Skipping GCP instances.")
    compute_v1 = None
    MetricServiceClient = None
    Aggregation = None
    TimeInterval = None
    ListTimeSeriesRequest = None

这消除了错误,但我无法导入 Google Cloud 数据。

python ubuntu google-cloud-sdk protobuf-python python-3.13
1个回答
0
投票

这是一个已知问题,许多其他人也报告过。

除了将 Python 降级到 3.12 并等待 protobuf 开发人员解决问题之外,似乎没有其他解决方法:https://github.com/protocolbuffers/protobuf/issues/18706

© www.soinside.com 2019 - 2024. All rights reserved.