不支持Gunicorn按文件名导入(模块)

时间:2015-11-11 17:05:00

标签: python containers gunicorn

我新创建了一个容器ubuntu并在虚拟环境中安装了所需的包。然后我通过python path /到/ my / file / X.py(在virualenv中)执行了预先存在的python服务代码,它运行正常。所以我用枪炮作为gunicorn -b 0.0.0.0:5000路径/到/ my / file / X:app(在virualenv中)执行但是我收到以下错误

2015-11-11 16:38:08 [19118] [INFO] Starting gunicorn 17.5
2015-11-11 16:38:08 [19118] [INFO] Listening at: http://0.0.0.0:444 (19118)
2015-11-11 16:38:08 [19118] [INFO] Using worker: sync
2015-11-11 16:38:08 [19123] [INFO] Booting worker with pid: 19123
2015-11-11 16:38:08 [19123] [ERROR] Exception in worker process:
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 473, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 115, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 33, in load
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 362, in import_app
    __import__(module)
ImportError: Import by filename is not supported.
Traceback (most recent call last):
  File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 473, in spawn_worker
    worker.init_process()
  File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 100, in init_process
    self.wsgi = self.app.wsgi()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 115, in wsgi
    self.callable = self.load()
  File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 33, in load
    return util.import_app(self.app_uri)
  File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 362, in import_app
    __import__(module)
ImportError: Import by filename is not supported.
2015-11-11 16:38:08 [19123] [INFO] Worker exiting (pid: 19123)
2015-11-11 16:38:09 [19118] [INFO] Shutting down: Master

任何人都可以帮我修复ImportError: Import by filename is not supported。它为什么要来?我在其他服务器上实现了gunicorn,它在那里工作正常。

3 个答案:

答案 0 :(得分:14)

就像错误说的那样:你不能通过文件路径引用Python模块,你必须从位于PYTHONPATH的目录开始的虚线模块路径引用它。

gunicorn -b 0.0.0.0:5000 path.inside.virtualenv.X:app

答案 1 :(得分:2)

我遇到了同样的问题,我使用myProxy

--chdir /path/to/project

希望这会有所帮助

答案 2 :(得分:0)

对于googlers来说,当我意外地使用gunicorn -paste而不是gunicorn -paste运行我的应用程序时,我也遇到了这个错误。 gunicorn没有错误,但没有找到api.ini并且它不支持'导入文件名不支持'错误。