'ImportError: cannot import name 'run_with_reloader' from 'werkzeug.serving'

I am getting the following error when I try to run the backend of my web application: ImportError: cannot import name 'run_with_reloader' from 'werkzeug.serving'. It is coming from within the \lib\site-packages\werkzeug\serving.py file. I think it has to do with the line from flask_socketio import SocketIO inside my server file. Any ideas?



Solution 1:[1]

This error has been addressed, so you are very likely using an old version of Flask-SocketIO. Once you upgrade the error should go away.

Solution 2:[2]

Solution is to install the following Werkzeug version (Werkzeug-0.10.2.dev0dev-20220510) along with the following versions: [Tested in MacOS]

pip3 install Flask-SocketIO==4.3.1

pip3 install python-engineio==3.13.2

pip3 install python-socketio==4.6.0

pip3 install git+https://github.com/untitaker/werkzeug.git@reloader-perf

Solution 3:[3]

I needed to keep using flask-socketio v4 (for older socketio.js) and pinning to 2.0.x version of Werkzeug fixed this problem

--- a/python-flask-socketio-server/requirements.txt
+++ b/python-flask-socketio-server/requirements.txt
@@ -1,4 +1,5 @@
 flask
+Werkzeug==2.0.1
 flask-socketio==4.3.2
 # wheel should not be needed, but avoids pyyaml paho-mqtt bdist_wheel error
 wheel

Note: I also needed to tell pip to not use cached packages, or else it would still pull in problematic 2.1.x version to virtualenv that was being regenerated.

pip install --no-cache-dir -r requirements.txt

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 Miguel Grinberg
Solution 2
Solution 3 popcnt