ImportError: cannot import name Namespace

See original GitHub issue

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.

Issue Analytics

  • State:closed
  • Created 6 years ago
  • Comments:8 (2 by maintainers)

github_iconTop GitHub Comments

15reactions
HaoYang0000commented, Jan 23, 2019

@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

5reactions
rishadfbcommented, Mar 5, 2018

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

Read more comments on GitHub >

github_iconTop Results From Across the Web

Heroku Flask Socketio cannot import name 'namespace'
Ah-Ha! Turns out yesterday when I was switching between eventlet/gevent, Heroku's dependency cache was storing both eventlet/gevent even ...
Read more >
Python cannot import name: How to Solve ImportError
To resolve the ImportError: Cannot import name, modify the x.py file. For example, instead of importing the y module at the start of...
Read more >
How to Fix : “ImportError: Cannot import name X” in Python
The following are the major reasons for the occurrence of "ImportError: cannot import name": The imported class is in a circular dependency.
Read more >
ImportError: cannot import name 'NAMESPACE'-django
I have searched all over for a solution but I cannot find one for the error I am getting. I am trying to...
Read more >
cannot import name 'PasswordHasher' from 'argon2'
2.9 on Ubuntu: cannot import name 'PasswordHasher' from 'argon2'. 53 views ... exec(code, namespace, namespace)
Read more >

github_iconTop Related Medium Post

No results found

github_iconTop Related StackOverflow Question

No results found

github_iconTroubleshoot Live Code

Lightrun enables developers to add logs, metrics and snapshots to live code - no restarts or redeploys required.
Start Free

github_iconTop Related Reddit Thread

No results found

github_iconTop Related Hackernoon Post

No results found

github_iconTop Related Tweet

No results found

github_iconTop Related Dev.to Post

No results found

github_iconTop Related Hashnode Post

No results found