'ImportError: cannot import name 'MutableMapping' from 'collections' (/app/.heroku/python/lib/python3.10/collections/__init__.py)
I'm trying to deploy my Flask app to a Heroku server, but I keep "Internal Server Error", and when I check the app error logs this is what I found:
Extract of Heroku error logs:
[...]
2022-03-26T02:07:20.728861+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/flask/sessions.py", line 14, in <module>
2022-03-26T02:07:20.728861+00:00 app[web.1]: from collections import MutableMapping
2022-03-26T02:07:20.728865+00:00 app[web.1]: ImportError: cannot import name 'MutableMapping' from 'collections'(/app/.heroku/python/lib/python3.10/collections/__init__.py)
2022-03-26T02:07:20.728865+00:00 app[web.1]: [2022-03-26 02:07:20 +0000] [10] [INFO] Worker exiting (pid: 10)
2022-03-26T02:07:20.825469+00:00 app[web.1]: Traceback (most recent call last):
2022-03-26T02:07:20.825566+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 209, in run
2022-03-26T02:07:20.825875+00:00 app[web.1]: self.sleep()
2022-03-26T02:07:20.825877+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 357, in sleep
2022-03-26T02:07:20.826299+00:00 app[web.1]: ready = select.select([self.PIPE[0]], [], [], 1.0)
2022-03-26T02:07:20.826300+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 242, in handle_chld
2022-03-26T02:07:20.826474+00:00 app[web.1]: self.reap_workers()
2022-03-26T02:07:20.826474+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.10/site-packages/gunicorn/arbiter.py", line 525, in reap_workers
2022-03-26T02:07:20.826714+00:00 app[web.1]: raise HaltServer(reason, self.WORKER_BOOT_ERROR)
2022-03-26T02:07:20.826715+00:00 app[web.1]: gunicorn.errors.HaltServer: <HaltServer 'Worker failed to boot.' 3>
[...]
The problem is that, as you may see, I don't use or import MutableMapping in any of my files, but some Python internal library file does, and that seems to be generating some error that doesn't allow me to run my app properly.
Does anyone had this problem before and knows how to solve it? I looked all over google but didn't find nothing related
Solution 1:[1]
These errors came from python 3.10 which is not stable yet, Heroku by default will use the latest python edition I suggest you should use 3.9. Add a "runtime.txt" in your code with body:
python-3.9.6 # or version you are using
Sources
This article follows the attribution requirements of Stack Overflow and is licensed under CC BY-SA 3.0.
Source: Stack Overflow
| Solution | Source |
|---|---|
| Solution 1 | Công Tu?n |
