Fixing Python and AWS CLI ImportError: cannot import name MutableMapping from ‘collections’

Python and AWS CLI ImportError: cannot import name ‘MutableMapping’ from ‘collections’ is an error which occurs sometimes when you use the AWS CLI.

Today, I will explain in detail why this error is happening and how to fix it in the most efficient way possible.

Exploring the Python and AWS CLI ImportError: cannot import name MutableMapping from ‘collections’

This is an error which occurs sometimes when you use the AWS CLI.

Please double check the error message bellow so you can avoid mixing between different errors.

MutableMapping from ‘collections’ problem banner

In the sections bellow we will explain the source of the problem and propose many possible fixes.

The Method that Fixed my issue : Fix AWS CLI and Python Compatibility Problems

This is a very popular problem that arises when you use the AWS CLI.

The problem here is that MutableMapping is not supported in Python 3.9 since it was removed entirely.

You are getting the error since the AWS CLI uses MutableMapping.

This is not a problem with your code, its a compatibility problem between the AWS CLI and python.

As of now, the best solution is to downgrade Python, that is a lot to ask but that is the best way to solve the problem.

You need a version of Python which came out before Python 3.9, Python 3.8 will do the trick.

EDIT as of October 2022:

It seems that a version of AWS CLI compatible to python 3.9 and even Python 3.10 and Python 3.11 has been released, you can check out the official page : https://pypi.org/project/awscli/

You can install AWSCLI 1.25.90 using pip like this:

                                                                       #
# You can install AWSCLI 1.25.90 using pip like this
pip install awscli
                                                                       #

I hope the fix above fixed your problem. Thank you for reading this article to the end, Good luck with your project.

Summing-up : 

This is the end of this article, I hope we helped you solve the error : cannot import name ‘MutableMapping’ from ‘collections’ or at least show you why it happens and guided you in the right direction. If you want to help, you can donate to our Kofi account.

Thank you for reading my blog post to the end, If you want to learn more about the Python programming language, check out the official Python Documentation : https://docs.python.org/3/