Issue
I am trying to use the flask_socketio library, following the documentation: https://python-socketio.readthedocs.io/en/latest/intro.html#what-is-socket-io
I have a file called socketio.py, and tried using their sample code:
from flask import Flask, render_template
from flask_socketio import SocketIO
app = Flask(__name__)
app.config['SECRET_KEY'] = 'secret!'
socketio = SocketIO(app)
if __name__ == '__main__':
socketio.run(app)
I get this error when trying to run it through python3 ($ python3 socketio.py)
Traceback (most recent call last):
File "socketio.py", line 2, in <module>
from flask_socketio import SocketIO
File "/usr/local/lib/python3.8/dist-packages/flask_socketio/__init__.py", line 21, in <module>
import socketio
File "socketio.py", line 2, in <module>
from flask_socketio import SocketIO
ImportError: cannot import name 'SocketIO' from partially initialized module 'flask_socketio' (most likely due to a circular import) (/usr/local/lib/python3.8/dist-packages/flask_socketio/__init__.py)
When I tried using flask run to run it , I get this error
Error: While importing "socketio", an ImportError was raised:
Traceback (most recent call last):
File "python3.8/site-packages/flask/cli.py", line 240, in locate_app
__import__(module_name)
File "socketio.py", line 2, in <module>
from flask_socketio import SocketIO
File "/usr/local/lib/python3.8/dist-packages/flask_socketio/__init__.py", line 22, in <module>
from socketio.exceptions import ConnectionRefusedError # noqa: F401
ModuleNotFoundError: No module named 'socketio.exceptions'; 'socketio' is not a package
I have tried uninstalling socketio and reinstalling and flask-socketio as there seems to be issues if you have both installed, but it still continues to give the same error.
Solution
I can see you have named your program socketio.py
. This is conflicting with socketio module used by flask_socketio
. Rename your filename and try running.
Answered By - Ritwik G
0 comments:
Post a Comment
Note: Only a member of this blog may post a comment.