我想单步浏览在带有PyCharm CE的Gunicorn下运行的Hello-World Flask应用程序。

该应用程序是通常位于/tmp/hello-world/app中的5-10衬纸,而venv位于/tmp/env中。

我的PyCharm配置如下:

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


该应用程序使用gunicorn app:app从该venv中的命令行正常运行,但是当我在PyCharm CE下启动服务器时,gunicorn内部的导入失败:

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.


无效的解决方案:


我在macOS和PyCharm CE 2016.3上没有看到"gevent compatible debugging"。近四年后,这个答案有意义吗?

最佳答案

错误非常明显。您正在尝试通过提供文件路径来按文件名导入。尝试将脚本参数更改为仅app:app,它将起作用。

关于python - 使用PyCharm在Gunicorn下调试Flask应用,我们在Stack Overflow上找到一个类似的问题:https://stackoverflow.com/questions/46207139/

10-16 08:43