简体   繁体   中英

ImportError: cannot import name 'MutableMapping' from 'collections'

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?

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

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM