4

I have installed the AWS CLI using pip on my Python 3.9.0a1 alpine Docker image. Installation went fine. When I run the aws command, I'm getting the following error.

aws
Traceback (most recent call last):
  File "/usr/local/bin/aws", line 27, in <module>
    sys.exit(main())
  File "/usr/local/bin/aws", line 23, in main
    return awscli.clidriver.main()
  File "/usr/local/lib/python3.9/site-packages/awscli/clidriver.py", line 68, in main
    driver = create_clidriver()
  File "/usr/local/lib/python3.9/site-packages/awscli/clidriver.py", line 77, in create_clidriver
    load_plugins(session.full_config.get('plugins', {}),
  File "/usr/local/lib/python3.9/site-packages/awscli/plugin.py", line 44, in load_plugins
    modules = _import_plugins(plugin_mapping)
  File "/usr/local/lib/python3.9/site-packages/awscli/plugin.py", line 61, in _import_plugins
    module = __import__(path, fromlist=[module])
  File "/usr/local/lib/python3.9/site-packages/awscli/handlers.py", line 42, in <module>
    from awscli.customizations.history import register_history_mode
  File "/usr/local/lib/python3.9/site-packages/awscli/customizations/history/__init__.py", line 24, in <module>
    from awscli.customizations.history.db import DatabaseConnection
  File "/usr/local/lib/python3.9/site-packages/awscli/customizations/history/db.py", line 19, in <module>
    from collections import MutableMapping
ImportError: cannot import name 'MutableMapping' from 'collections' (/usr/local/lib/python3.9/collections/__init__.py)



python --version
Python 3.9.0a1

Do I need to install any other module to fix this error message?

Gino Mempin
  • 19,150
  • 23
  • 79
  • 104
sfgroups
  • 16,514
  • 23
  • 105
  • 182

2 Answers2

6

collections.MutableMapping has been deprecated since Python 3.3, and was officially removed since Python 3.9.

Excerpt from the documentation:

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

You can either wait for a Python 3.9-compatible version of awscli to be released, or patch the aws script (under your /usr/local/bin) yourself like this for the time being:

...
import collections
from collections import abc
collections.MutableMapping = abc.MutableMapping
import awscli.clidriver
blhsing
  • 77,832
  • 6
  • 59
  • 90
0

I also encountered this error and was not able to get the import work arounds to work.

I did run my work on Google Colab https://colab.research.google.com/ which works a bit like Jupyter Notebook and the code ran fine without having the the MutableMapping issue. I realize that this is not ideal for every user case, but it is a workaround.

Christopher
  • 137
  • 3
  • 14
  • It probably only worked because your colab/notebook was using a Python version < 3.9. From [As of 2021, which python version is Google Colab using](https://stackoverflow.com/a/65912526/2745495): "*Note that as of April 2020, Colab uses Python 3.6.9 which should run everything without any errors.*" The moment Google Colab allows / switches to 3.9, it will also probably break. – Gino Mempin Jun 05 '22 at 02:45