ImportError: cannot import name 'MutableMapping' from 'collections' (/usr/local/lib/python3.10/collections/__init__.py)

Viewed 8353

I'm running this simple flask app in vs code. Dockerized it and loaded to ECS. The task is exiting with the following error:

ImportError: cannot import name 'MutableMapping' from 'collections' (/usr/local/lib/python3.10/collections/init.py)

The base image I'm using is python3.10.

Following is the dockerfile code:

FROM python:3.10
WORKDIR /usr/src/app
COPY . .
RUN pip install --no-cache-dir -r requirements.txt
EXPOSE 5000

Why am I getting this error?

3 Answers

Trying the following in python 3.9:

>>> from collections import MutableMapping
<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

So I'm guessing your problem is you're using python 3.10 where you need to do:

>>> from collections.abc import MutableMapping

if you update the flask package to >=2.0 it will import it correctly also in python 3.10

Looks like you're doing the same docker tutorial that I am.

@geza.denes is right, we need flask 2.0 or greater.

you can update this in flask-app/requirements.txt

Rebuild your docker image and run it again, should work!

Related