gcloud on Python 3.10: module ‘collections’ has no attribute ‘Mapping’

The CPython documentation says about collections.Mapping and other abstract base classes:

Deprecated since version 3.3, will be removed in version 3.10: Moved Collections Abstract Base Classes to the collections.abc module.

Fedora 35 uses CPython 3.10 as its default Python interpreter. Here, invoking Google’s gcloud CLI fails with

ERROR: gcloud failed to load: module 'collections' has no attribute 'Mapping'

Observed with Google Cloud SDK release 363.0.0 (2021-11-02).

I addressed this by installing Python 2.7 and then instructing gcloud to use that:

$ sudo dnf install python2.7
$ export CLOUDSDK_PYTHON="/usr/bin/python2"
$ gcloud

I reported that here.

Leave a Reply to rufo Cancel reply

Your email address will not be published. Required fields are marked *

Human? Please fill this out: * Time limit is exhausted. Please reload CAPTCHA.

  1. hipertracker Avatar
    hipertracker

    It can be Python 3 but older than 3.10. This is also working:

    export CLOUDSDK_PYTHON="$HOME/.asdf/installs/python/3.9.11/bin/python"

  2. Matthew Broadhead Avatar
    Matthew Broadhead

    Thanks, that worked for me

  3. hoffmanc707 Avatar
    hoffmanc707

    Thank you – smart solution.

  4. rufo Avatar
    rufo

    Thank you! I encountered this problem too.