Flask-socketio: ImportError: cannot import name Namespace

Created on 5 Mar 2018  路  7Comments  路  Source: miguelgrinberg/Flask-SocketIO

I am trying to run the app.py from the examples folder inside a virtual environment with Python 2.7.

This is my output for running app.py:

$ python scripts/python/app.py
Traceback (most recent call last):
  File "scripts/python/app.py", line 4, in <module>
    from flask_socketio import SocketIO, emit, join_room, leave_room, \
  File "/home/username/.local/lib/python2.7/site-packages/flask_socketio/__init__.py", line 23, in <module>
    from .namespace import Namespace
  File "/home/username/.local/lib/python2.7/site-packages/flask_socketio/namespace.py", line 1, in <module>
    from socketio import Namespace as _Namespace
ImportError: cannot import name Namespace

I saw some comments suggesting a manual upgrade but that didn't work for me:

pip install --upgrade flask-socketio                                                                                                                                                                       feature/pythonSocketServer [bac96ba] modified untracked
Requirement already up-to-date: flask-socketio in /home/username/.local/lib/python2.7/site-packages
Requirement already up-to-date: python-socketio>=1.6.1 in /home/username/.local/lib/python2.7/site-packages (from flask-socketio)
Requirement already up-to-date: Flask>=0.9 in /home/username/.local/lib/python2.7/site-packages (from flask-socketio)
Requirement already up-to-date: six>=1.9.0 in /usr/lib/python2.7/site-packages (from python-socketio>=1.6.1->flask-socketio)
Requirement already up-to-date: python-engineio>=1.2.1 in /home/username/.local/lib/python2.7/site-packages (from python-socketio>=1.6.1->flask-socketio)
Requirement already up-to-date: Jinja2>=2.4 in /usr/lib/python2.7/site-packages (from Flask>=0.9->flask-socketio)
Requirement already up-to-date: Werkzeug>=0.7 in /home/username/.local/lib/python2.7/site-packages (from Flask>=0.9->flask-socketio)
Requirement already up-to-date: click>=2.0 in /home/username/.local/lib/python2.7/site-packages (from Flask>=0.9->flask-socketio)
Requirement already up-to-date: itsdangerous>=0.21 in /home/username/.local/lib/python2.7/site-packages (from Flask>=0.9->flask-socketio)
Requirement already up-to-date: MarkupSafe>=0.23 in /usr/lib/python2.7/site-packages (from Jinja2>=2.4->Flask>=0.9->flask-socketio)

I have a setup.py file for my project which includes the following line:

install_requires=['pybluez', 'flask-socketio']

I also tried replacing my setup.py with the requirements.txt from here.

question

Most helpful comment

@minusplusminus @diptopratyaksa I was having the same issue, by re-install python-socketio
pip uninstall python-socketio
pip install python-socketio

Ref: https://github.com/miguelgrinberg/Flask-SocketIO/issues/164#issuecomment-228199584

All 7 comments

I had a folder called socketio in my project directory that was causing this.

Hi,
i'm having the same issue, but I don't have an folder named socketio


Traceback (most recent call last):
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 174, in _run_module_as_main
    "__main__", fname, loader, pkg_name)
  File "/usr/local/Cellar/python@2/2.7.15_1/Frameworks/Python.framework/Versions/2.7/lib/python2.7/runpy.py", line 72, in _run_code
    exec code in run_globals
  File "/Users/martijnmellema/Documents/Development/Projecten/Minusplusminus/research/ThermOS/__main__.py", line 1, in <module>
    import thermostat_web
  File "/Users/martijnmellema/Documents/Development/Projecten/Minusplusminus/research/ThermOS/thermostat_web.py", line 11, in <module>
    from flask_socketio import SocketIO
  File "/usr/local/lib/python2.7/site-packages/flask_socketio/__init__.py", line 23, in <module>
    from .namespace import Namespace
  File "/usr/local/lib/python2.7/site-packages/flask_socketio/namespace.py", line 1, in <module>
    from socketio import Namespace as _Namespace
ImportError: cannot import name Namespace

running on python 2.7.15 on the latest version of flask-socketio

@minusplusminus what is the output of pip freeze?

Same story with me. I looked into my /usr/local/lib/python3.5/site-packages/flask_socketio/
and guess what.. there is no file called namespace!

are you doing from flask_socketio import Namespace or from socketio import Namespace? If the latter, then you need to look in the socketio package, right?

@minusplusminus @diptopratyaksa I was having the same issue, by re-install python-socketio
pip uninstall python-socketio
pip install python-socketio

Ref: https://github.com/miguelgrinberg/Flask-SocketIO/issues/164#issuecomment-228199584

Before re-installing python-socketio, I had to do this: pip uninstall socketio. This one interferes with python-socketio....

Was this page helpful?
0 / 5 - 0 ratings

Related issues

EndenDragon picture EndenDragon  路  3Comments

chaitanyavolkaji picture chaitanyavolkaji  路  3Comments

benjaminturley picture benjaminturley  路  4Comments

huangganggui picture huangganggui  路  3Comments

dlernz picture dlernz  路  4Comments