Calaf
Calaf

Reputation: 10847

Debugging a Flask app under gunicorn with PyCharm

I'd like to single-step through a Hello-World Flask app running under Gunicorn with PyCharm CE.

The app is the usual 5-10 liner sitting in /tmp/hello-world/app, and the venv is in /tmp/env.

My PyCharm configuration looks like this:

Script: /tmp/env/bin/gunicorn
Script parameters: /tmp/hello-world/app:app
Working directory: /tmp/hello-world

The app runs fine from the command line in that venv using gunicorn app:app, but when I launch the server under PyCharm CE, an import internal to gunicorn fails:

Traceback (most recent call last):
  File "/tmp/env/lib/python2.7/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
    worker.init_process()
  File "/tmp/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 126, in init_process
    self.load_wsgi()
  File "/tmp/env/lib/python2.7/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
    self.wsgi = self.app.wsgi()
  File "/tmp/env/lib/python2.7/site-packages/gunicorn/app/base.py", line 67, in wsgi
    self.callable = self.load()
  File "/tmp/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
    return self.load_wsgiapp()
  File "/tmp/env/lib/python2.7/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
    return util.import_app(self.app_uri)
  File "/tmp/env/lib/python2.7/site-packages/gunicorn/util.py", line 352, in import_app
    __import__(module)
ImportError: Import by filename is not supported.

Solutions that don't work:

Upvotes: 1

Views: 2375

Answers (1)

Kyle Stuart
Kyle Stuart

Reputation: 111

The error is pretty clear. You're trying to import by file name by giving it a file path. Try changing your script parameters to just app:app and it should work.

Upvotes: 1

Related Questions