Flask-socketio: error when run exemple v1.0

Created on 23 Oct 2015  路  31Comments  路  Source: miguelgrinberg/Flask-SocketIO

this is my virtualenv:

(socket-exemple)[hugo:Flask-SocketIO](v1.0)$ pip freeze
Flask==0.10.1
Flask-SocketIO==1.0b4
gevent==1.0.2
gevent-websocket==0.9.5
greenlet==0.4.9
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
python-engineio==0.7.1
python-socketio==0.6.0
six==1.10.0
Werkzeug==0.10.4

I'm trying to run the example but get the error below:

(socket-exemple)[hugo:Flask-SocketIO](v1.0)$ python example/app.py
async_mode is gevent
Traceback (most recent call last):
  File "example/app.py", line 39, in <module>
    from flask_socketio import SocketIO, emit, join_room, leave_room, \
  File "/Users/hugo/envs/socket-exemple/lib/python2.7/site-packages/flask_socketio/__init__.py", line 3, in <module>
    import socketio
ImportError: No module named socketio

What am I doing wrong ?

enhancement

Most helpful comment

Uninstalling and reinstalling python-socketio worked for me. Seems to be a linking issue.
pip uninstall python-socketio
pip install python-socketio

All 31 comments

Please uninstall gevent-socketio. A few people are having this problem, I'll see if I can figure out a way to return a meaningful error message.

gevent-socketio is not installed.

(socket-exemple)[hugo:Flask-SocketIO](v1.0)$ pip uninstall gevent-socketio
Cannot uninstall requirement gevent-socketio, not installed

Are you using gevent for anything? If not, try uninstalling gevent and gevent-websocket

@hugoantunes Did you install the new requirements for the 1.0 version, namely python-socketio?

@ktoh i think the problem is related to python-socketio.

@miguelgrinberg yes, but for some reason is not in my python package. When I try to import in the python terminal the package was not found.

@hugoantunes Does everything work if you create a brand new virtualenv and install Flask-SocketIO 1.0b4 in it?

Thank you guys !!!
I really don't know where was my problem but when I created my virtualenv again everything started run fine.
I was finally able to test everything with gevent-websocket too.

just to show you that is my virtualenv now:

(exemple-socketio)[hugo@ironhide2:Flask-SocketIO](v1.0)$ pip freeze
Flask==0.10.1
-e [email protected]:hugoantunes/Flask-SocketIO.git@b935954b671665ea2b2354ce739cdaaad2050342#egg=Flask_SocketIO-origin/v1.0
Jinja2==2.8
MarkupSafe==0.23
Werkzeug==0.10.4
gevent==1.0.2
gevent-websocket==0.9.5
greenlet==0.4.9
itsdangerous==0.24
python-engineio==0.7.1
python-socketio==0.6.0
six==1.10.0
wsgiref==0.1.2

@miguelgrinberg although the issue is caused by incorrect dependency installation and/or python path, the socketio namespace is used by a few different libraries so that makes the issue harder to debug.

Might be worth doing a check at module load time that spits out a warning if a non engineio based socket library is loaded (or not found)

@ktoh Yes, that's not a bad idea, I can add that.

Added a check that error if gevent-socketio is found, to be released with v1.1.

Uninstalling and reinstalling python-socketio worked for me. Seems to be a linking issue.
pip uninstall python-socketio
pip install python-socketio

This works for me ^

I had the same issue where I got
nosocketio

then, I uninstalled python-socketio and reinstalled it but now when I run the app it gets stuck in gevent\hub.py in switch line 630
socketioblock

Before I installed the gevent and gevent-websocket libraries, the code had no problem running.
Did someone fix the part where gevent's code gets stuck ?

@magaliet have you upgraded gevent? If you are using it from the old days of gevent-socketio, you should try a more recent version.

I just installed it from the command line :

$pip install gevent

(it's gevent-1.2.1)

@magaliet Can you show me the output of pip freeze? Also, the stack trace does not really show anything odd, gevent does not appear hung, it is just in the event loop.

@miguelgrinberg , thank you for your fast replies !

here is the output of pip freeze:
pipfreeze

I interrupted the execution because it was taking more than 30 minutes, and I don't understand why it was stuck where it is for so long. I tried rerunning it and interrupting it earlier and it showed the same stack trace.

Was it stuck, or waiting for requests? Did you try sending a request to see if it was listening?

Also, are you using Python 2 or 3? The gevent-websocket package only works with Python 2.

I am using Python 2.7.12.

I assumed it was stuck because when I run the app on the Flask development server, I am told where that the app is running on localhost after I run the code, whereas, now nothing is outputted after I run the code.

I am just starting using websockets and Flask-socketio so it is very possible that it was not stuck and I misinterpreted what was happening. I will try to create a client and send a request to see if it is listening and then update you on what happened.

I tried with your example code from :
https://blog.miguelgrinberg.com/post/easy-websockets-with-flask-and-gevent

and it is running, so it must have been due to the code I ran, I will change my code..

Thank you for your help and time @miguelgrinberg !!

Yeah, I suspected that was the misunderstanding. The Flask web server is friendlier, more so if you run in debug mode.

ImportError: No module named 'flask_socketio'

I got this error when I ran my flask app using:

$ python _appfile.py_

ONLY after installing either gevent or eventlet, but it was 'fixed' when I used:

$ export FLASK_APP=_appfile.py_

(Or I stopped breaking it!)

Just putting this here for anyone else with the same mistake.

python==3.6
Flask==0.12.2
Flask-SocketIO==2.9.3

Traceback (most recent call last):
File "C:/Development/server.py", line 6, in
from flask_socketio import SocketIO, emit, join_room
File "C:\Python27\lib\site-packages\flask_socketio__init__.py", line 22, in
from .namespace import Namespace
File "C:\Python27\lib\site-packages\flask_socketio\namespace.py", line 1, in
from socketio import Namespace as _Namespace
ImportError: cannot import name Namespace

My code part is like this.
_from flask_socketio import SocketIO, emit_

I have a separate virtual env for this.

My pip freeze is like this.
_Flask==0.10.1
Flask-SocketIO==2.9.3
gevent==1.0.2
gevent-socketio==0.3.6
gevent-websocket==0.9.5
greenlet==0.4.9
itsdangerous==0.24
Jinja2==2.8
MarkupSafe==0.23
python-engineio==2.0.2
python-socketio==1.8.4
six==1.10.0
ujson==1.33
Werkzeug==0.10.4_

@chandulaPerera As I mentioned above, please uninstall gevent-socketio. That is an old package that is not used by Flask-SocketIO, and has a name collision with a package that is used.

Below is my pip freeze output
aniso8601==3.0.2
cffi==1.11.5
click==6.7
Django==2.0.7
Flask==1.0.2
Flask-Cors==3.0.6
Flask-RESTful==0.3.6
Flask-SocketIO==3.0.1
gevent==1.3.5
greenlet==0.4.14
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
pycparser==2.18
python-engineio==2.2.0
python-socketio==2.0.0
pytz==2018.5
six==1.11.0
Werkzeug==0.14.1

I am getting below error when i tried the example . Can you help me with this @miguelgrinberg

File "socketio.py", line 2, in
from flask_socketio import SocketIO, emit
File "C:\Users\abcde\AppData\Local\Programs\Python\Python35\lib\site-packages\flask_socketio__init__.py", line 16, in
import socketio
File "C:\Users\abcde\Desktopsocketio.py", line 2, in
from flask_socketio import SocketIO, emit
ImportError: cannot import name 'SocketIO'

You have a file named socketio.py in your top-level directory. That name shadows the socketio package. Rename your file to some other name.

@chrislgarry this worked, thanks

hello everyone, iam a bit confused with code, when I run this
-->/usr/bin/gunicorn --worker-class eventlet -w 1 run:app -b 127.0.0.1:7570
the code runs well, but when i include the same code in a service i get this error
--> gunicorn[5585]: ImportError: No module named flask_socketio

what can I do to sole this

@ssebina are you running your service with the correct virtual environment?

yes please thanks for the response, actually the problem was that I hadn't installed the module as a super user, but I googled around and found the solution

Hi,
have got the same problem:
ModuleNotFoundError: No module named 'flask_socketio'
Here is a part of my freeze:

Flask==1.0.4
gevent==1.4.0
python-socketio==4.3.0
flask-socketio==4.2.0

Having this error on both Py3.6 & Py3.7
export FLASK_APP won't help.

Update gunicorn was the issue, sorry.

Was this page helpful?
0 / 5 - 0 ratings

Related issues

AlaaKho picture AlaaKho  路  3Comments

hrmon picture hrmon  路  5Comments

EndenDragon picture EndenDragon  路  3Comments

nh916 picture nh916  路  3Comments

chaitanyavolkaji picture chaitanyavolkaji  路  3Comments