解决在 Google Cloud Platform 上安装或构建时发现的属性错误

Esh*_*tty 13 python gcloud

所以我有 python 版本 3.8.12,在尝试构建 cloudrun 应用程序时,我收到错误:

ERROR: gcloud failed to load: module 'collections' has no attribute 'Mapping'
Run Code Online (Sandbox Code Playgroud)

现在,当我尝试再次运行并安装 Gcloud SDK 时,出现错误:

Welcome to the Google Cloud SDK! Traceback (most recent call last):   File "/Users/eshanchatty/downloads/./google-cloud-sdk/bin/bootstrapping/install.py", line 12, in <module>
    import bootstrapping   File "/Users/eshanchatty/Downloads/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 46, in <module>
    from googlecloudsdk.core.updater import update_manager   File "/Users/eshanchatty/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py", line 39, in <module>
    from googlecloudsdk.core.console import progress_tracker   File "/Users/eshanchatty/Downloads/google-cloud-sdk/lib/googlecloudsdk/core/console/progress_tracker.py", line 651, in <module>
    class _BaseStagedProgressTracker(collections.Mapping): AttributeError: module 'collections' has no attribute 'Mapping'
Run Code Online (Sandbox Code Playgroud)

这是什么原因造成的,我该如何解决这个问题?

Map*_*SVK 21

昨天我将Fedora更新到了35版本。该版本默认使用Python 3.10。

在此版本中,集合没有Mapping。我遇到了和你一样的错误。

我没有尝试过重新安装 Google Cloud SDK。相反,我将这一行写入我的~/.bashrc文件中:

export CLOUDSDK_PYTHON=python2
Run Code Online (Sandbox Code Playgroud)

然后关闭并打开终端。

现在 SDK 使用 Python 2 而不是 Python 3。这解决了我的问题。

  • 在 Debian 11 上,也安装了 python 10.0,我使用 `export CLOUDSDK_PYTHON=python3.9` 并且它对我有用 (6认同)