title: 'no module named <site>' Flask, Gunicorn, Nginx
body: <p>My site has been running more or less fine for ~1.5 years. I occasionally experience an intermittent power outage which requires me to restart nginx and gunicorn. About 1.5 months ago my server was out of space which similarly required me to clear some space and also reboot nginx/gunicorn. </p>
  
  <p>In each case I was faced with a 502 Bad Gateway error, but rebooting nginx/gunicorn solved the problem. </p>
  
  <p>Yet again, I am faced with a 502 Bad Gateway error but restarting the server does not work. Instead, I get the following issue when running the command below: </p>
  
  <pre><code>/var/www/sonification/sonification/venv/bin/gunicorn --bind 127.0.0.1:5001 --worker-class socketio.sgunicorn.GeventSocketIOWorker sonification:app
  </code></pre>
  
  <p>There are no changes to my server configuration. Everything has worked in the past! I don't even know the first step to debugging something like this. Any pointers? </p>
  
  <pre><code>user@site:/var/www/sonification/sonification$ source venv/bin/activate
  (venv)user@site:/var/www/sonification/sonification$ pip freeze
  /var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/pip/_vendor/requests/packages/urllib3/util/ssl_.py:90: InsecurePlatformWarning: A true SSLContext object is not available. This prevents urllib3 from configuring SSL appropriately and may cause certain SSL connections to fail. For more information, see https://urllib3.readthedocs.org/en/latest/security.html#insecureplatformwarning.
    InsecurePlatformWarning
  You are using pip version 7.0.1, however version 9.0.1 is available.
  You should consider upgrading via the 'pip install --upgrade pip' command.
  Flask==0.10.1
  Flask-Bootstrap==3.3.4.1
  Flask-SocketIO==0.6.0
  gevent==1.0.2
  gevent-socketio==0.3.6
  gevent-websocket==0.9.3
  greenlet==0.4.7
  gunicorn==18.0
  itsdangerous==0.24
  Jinja2==2.7.3
  MarkupSafe==0.23
  uWSGI==2.0.10
  Werkzeug==0.10.4
  wheel==0.24.0
  (venv)user@site:/var/www/sonification/sonification$ gunicorn --bind 127.0.0.1:5002 --worker-class socketio.sgunicorn.GeventSocketIOWorker sonification:app
  2017-06-28 14:59:45 [23115] [INFO] Starting gunicorn 18.0
  2017-06-28 14:59:45 [23115] [INFO] Listening at: http://127.0.0.1:5002 (23115)
  2017-06-28 14:59:45 [23115] [INFO] Using worker: socketio.sgunicorn.GeventSocketIOWorker
  2017-06-28 14:59:45 [23120] [INFO] Booting worker with pid: 23120
  2017-06-28 14:59:45 [23120] [ERROR] Exception in worker process:
  Traceback (most recent call last):
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
      worker.init_process()
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
      self.wsgi = self.app.wsgi()
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
      self.callable = self.load()
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
      return self.load_wsgiapp()
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
      return util.import_app(self.app_uri)
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
      __import__(module)
  ImportError: No module named sonification
  Traceback (most recent call last):
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
      worker.init_process()
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
      self.wsgi = self.app.wsgi()
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
      self.callable = self.load()
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
      return self.load_wsgiapp()
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
      return util.import_app(self.app_uri)
    File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
      __import__(module)
  ImportError: No module named sonification
  2017-06-28 14:59:45 [23120] [INFO] Worker exiting (pid: 23120)
  2017-06-28 14:59:45 [23115] [INFO] Shutting down: Master
  2017-06-28 14:59:45 [23115] [INFO] Reason: Worker failed to boot.
  </code></pre>
  
  <p>Have also tried: </p>
  
  <pre><code>  user@site:/var/cache$ /var/www/sonification/sonification/venv/bin/gunicorn --bind 127.0.0.1:5001 --worker-class socketio.sgunicorn.GeventSocketIOWorker sonification:app
      2017-06-25 16:51:12 [6352] [INFO] Starting gunicorn 18.0
      2017-06-25 16:51:12 [6352] [INFO] Listening at: http://127.0.0.1:5001 (6352)
      2017-06-25 16:51:12 [6352] [INFO] Using worker: socketio.sgunicorn.GeventSocketIOWorker
      2017-06-25 16:51:12 [6357] [INFO] Booting worker with pid: 6357
      2017-06-25 16:51:12 [6357] [ERROR] Exception in worker process:
      Traceback (most recent call last):
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
          worker.init_process()
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
          self.wsgi = self.app.wsgi()
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
          self.callable = self.load()
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
          return self.load_wsgiapp()
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
          return util.import_app(self.app_uri)
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
          __import__(module)
      ImportError: No module named sonification
      Traceback (most recent call last):
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/arbiter.py", line 495, in spawn_worker
          worker.init_process()
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/workers/base.py", line 106, in init_process
          self.wsgi = self.app.wsgi()
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/base.py", line 114, in wsgi
          self.callable = self.load()
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 62, in load
          return self.load_wsgiapp()
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 49, in load_wsgiapp
          return util.import_app(self.app_uri)
        File "/var/www/sonification/sonification/venv/local/lib/python2.7/site-packages/gunicorn/util.py", line 354, in import_app
          __import__(module)
      ImportError: No module named sonification
      2017-06-25 16:51:12 [6357] [INFO] Worker exiting (pid: 6357)
      2017-06-25 16:51:12 [6352] [INFO] Shutting down: Master
      2017-06-25 16:51:12 [6352] [INFO] Reason: Worker failed to boot.
  </code></pre>