Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How to fix "AttributeError: module 'collections' has no attribute 'Mapping'" with Google Cloud SDK package?

I tried to install Google Cloud SDK on macOS, but it shows the following error.

Can anyone help please?

"Welcome to the Google Cloud SDK!
Traceback (most recent call last):
  File "/Users/kaab/google-cloud-sdk/bin/bootstrapping/install.py", line 12, in <module>
    import bootstrapping
  File "/Users/kaab/google-cloud-sdk/bin/bootstrapping/bootstrapping.py", line 46, in <module>
    from googlecloudsdk.core.updater import update_manager
  File "/Users/kaab/google-cloud-sdk/lib/googlecloudsdk/core/updater/update_manager.py", line 39, in <module>
    from googlecloudsdk.core.console import progress_tracker
  File "/Users/kaab/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'"
like image 282
Khan Avatar asked Feb 17 '26 00:02

Khan


1 Answers

Are you running Python 3.10 or newer? Switch to an older Python version, or if you can edit the code, change the import statement to from collections.abc import Mapping.

When I import from collections import Mapping in Python 3.9, I get the message:

<stdin>:1: DeprecationWarning: Using or importing the ABCs
  from 'collections' instead of from 'collections.abc' is deprecated
  since Python 3.3, and in 3.10 it will stop working

(ABC stands for abstract base class.)

This means that ever since Python 3.3, the correct way to import this is from collections.abc import Mapping, and the old way finally stopped working in Python 3.10.

I'd call it a bug in Google Cloud SDK, but their documentation (at the time of the question) actually suggests to use Python 3.5 to 3.8, so I suspect they have not tested it on 3.10.

Edit: apparently Cloud SDK now (January 2024) says it supports up to 3.12. Presumably they have fixed the import. This answer might still be relevant to people who face this deprecation issue in other libraries.

like image 62
Dronir Avatar answered Feb 18 '26 15:02

Dronir