0
votes

Error:

from socketio import Namespace as _Namespace
ImportError: cannot import name 'Namespace'

code: https://github.com/ncd2dq/nickdima_site/tree/master/nickdima I've added the comment #CAUSES PROBLEM above all lines of code that are in question. It's only where ever I'm trying to import flask_socketio. The Only files that are relevant in my repo are nickdima>init.py and nickdima>test_pong>pong.py

I do not have any files / folders in my project with "socketio" in their name.

I've been trying to get Flask-Socketio to work for sometime now, see my other open question here (Flask-Socketio takes extremely long to connect on Heroku) and in trying to solve that issue I've somehow caused the below error (from heroku logs):

2018-09-03T16:07:40.660720+00:00 app[web.1]: [2018-09-03 16:07:40 +0000] [4] [INFO] Starting gunicorn 19.9.0
2018-09-03T16:07:40.661314+00:00 app[web.1]: [2018-09-03 16:07:40 +0000] [4] [INFO] Listening at: http://0.0.0.0:54684 (4)
2018-09-03T16:07:40.667073+00:00 app[web.1]: [2018-09-03 16:07:40 +0000] [8] [INFO] Booting worker with pid: 8
2018-09-03T16:07:40.661426+00:00 app[web.1]: [2018-09-03 16:07:40 +0000] [4] [INFO] Using worker: eventlet
2018-09-03T16:07:41.193765+00:00 app[web.1]: [2018-09-03 16:07:41 +0000] [8] [ERROR] Exception in worker process
2018-09-03T16:07:41.193787+00:00 app[web.1]: Traceback (most recent call last):
2018-09-03T16:07:41.193789+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/arbiter.py", line 583, in spawn_worker
2018-09-03T16:07:41.193791+00:00 app[web.1]: worker.init_process()
2018-09-03T16:07:41.193793+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/geventlet.py", line 102, in init_process
2018-09-03T16:07:41.193794+00:00 app[web.1]: super(EventletWorker, self).init_process()
2018-09-03T16:07:41.193796+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 129, in init_process
2018-09-03T16:07:41.193797+00:00 app[web.1]: self.load_wsgi()
2018-09-03T16:07:41.193799+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/workers/base.py", line 138, in load_wsgi
2018-09-03T16:07:41.193800+00:00 app[web.1]: self.wsgi = self.app.wsgi()
2018-09-03T16:07:41.193802+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
2018-09-03T16:07:41.193803+00:00 app[web.1]: self.callable = self.load()
2018-09-03T16:07:41.193805+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load
2018-09-03T16:07:41.193806+00:00 app[web.1]: return self.load_wsgiapp()
2018-09-03T16:07:41.193807+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 41, in load_wsgiapp
2018-09-03T16:07:41.193809+00:00 app[web.1]: return util.import_app(self.app_uri)
2018-09-03T16:07:41.193812+00:00 app[web.1]: __import__(module)
2018-09-03T16:07:41.193810+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/gunicorn/util.py", line 350, in import_app
2018-09-03T16:07:41.193813+00:00 app[web.1]: File "/app/nickdima/wsgi.py", line 5, in <module>
2018-09-03T16:07:41.193815+00:00 app[web.1]: from __init__ import create_app
2018-09-03T16:07:41.193818+00:00 app[web.1]: from flask_socketio import SocketIO
2018-09-03T16:07:41.193816+00:00 app[web.1]: File "/app/nickdima/__init__.py", line 5, in <module>
2018-09-03T16:07:41.193819+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask_socketio/__init__.py", line 23, in <module>
2018-09-03T16:07:41.193820+00:00 app[web.1]: from .namespace import Namespace
2018-09-03T16:07:41.193822+00:00 app[web.1]: File "/app/.heroku/python/lib/python3.6/site-packages/flask_socketio/namespace.py", line 1, in <module>
2018-09-03T16:07:41.193823+00:00 app[web.1]: from socketio import Namespace as _Namespace
2018-09-03T16:07:41.193825+00:00 app[web.1]: ImportError: cannot import name 'Namespace'
2018-09-03T16:07:41.194220+00:00 app[web.1]: [2018-09-03 16:07:41 +0000] [8] [INFO] Worker exiting (pid: 8)
2018-09-03T16:07:41.266303+00:00 app[web.1]: [2018-09-03 16:07:41 +0000] [4] [INFO] Shutting down: Master
2018-09-03T16:07:41.266389+00:00 app[web.1]: [2018-09-03 16:07:41 +0000] [4] [INFO] Reason: Worker failed to boot.
2018-09-03T16:07:41.411382+00:00 heroku[web.1]: State changed from starting to crashed
2018-09-03T16:07:41.393418+00:00 heroku[web.1]: Process exited with status 3
2018-09-03T16:07:42.980487+00:00 heroku[router]: at=error code=H10 desc="App cr

In my troubleshooting I was switching back and forth between guinicorn versions as well as iinstalling/uninstalling gevent/eventlet

Here's my current requirements.txt file:

click==6.7
dnspython==1.15.0
eventlet==0.24.1
Flask==1.0.2
Flask-SocketIO==3.0.1
greenlet==0.4.14
gunicorn==19.9.0
itsdangerous==0.24
Jinja2==2.10
MarkupSafe==1.0
monotonic==1.5
python-engineio==2.2.0
python-socketio==2.0.0
six==1.11.0
Werkzeug==0.14.1
1

1 Answers

0
votes

Ah-Ha!

Turns out yesterday when I was switching between eventlet/gevent, Heroku's dependency cache was storing both eventlet/gevent even when I would remove them from my requirements.txt and it would say "uninstalling gevent" or "uninstalling eventlet". This caused the issue.

To clear the cache I changed my python runtime based on this: https://devcenter.heroku.com/articles/python-runtimes