gunicorn:没有名为'wsgi'的模块

时间:2018-01-05 20:47:18

标签: python docker flask gunicorn

我有一个设置为使用docker运行的项目一台机器是ubuntu我运行得很好但是最近我试图在我的Windows笔记本电脑上运行它并得到一个ModuleNotFoundError。

Response [https://www.facebook.com/unsupportedbrowser]
  Date: 2018-01-05 21:39
  Status: 200
  Content-Type: text/html; charset=UTF-8
  Size: 309 kB
 <!DOCTYPE html>
<html lang="en" id="facebook" class="no_js">
<head><meta charset="utf-8" /><meta name="referrer" content="default" 
id="meta_referrer" /><script>window._cstart=+new Date();</script>...
<link type="text/css" rel="stylesheet" 
href="https://static.xx.fbcdn.net/rsrc.php/v3/yl/l/0,cross/Ms7B4ehALEW.css" 
data-bootloader-hash...
<link type="text/css" rel="stylesheet" 
href="https://static.xx.fbcdn.net/rsrc.php/v3/y3/l/0,cross/684seag7DTg.css" 
data-bootloader-hash...
<link type="text/css" rel="stylesheet" 
href="https://static.xx.fbcdn.net/rsrc.php/v3/yK/l/0,cross/g8YvVQ4GaAa.css" 
data-bootloader-hash...
<link type="text/css" rel="stylesheet" 
href="https://static.xx.fbcdn.net/rsrc.php/v3/yY/l/0,cross/423Tvkgz0LR.css" 
data-bootloader-hash...
<link type="text/css" rel="stylesheet" 
href="https://static.xx.fbcdn.net/rsrc.php/v3/y1/l/0,cross/leqp1EQMeCH.css" 
data-bootloader-hash...
<script src="https://static.xx.fbcdn.net/rsrc.php/v3/yC/r/3-Z0DsUATk-.js" 
data-bootloader-hash="+/Mwn" crossorigin="anonymous"></script>
<script>requireLazy(["ix"],function(ix){ix.add({"125923":
{"sprited":true,"spriteCssClass":"sx_4ccccf","spriteMapCssClass":"sp_lM6-
CJgzF...
...

我检查过以确保路径的环境变量设置正确。是否有任何常见的枪支问题可能会导致这些或其他事情成为明显的检查?

此容器的dockerfile如下:

[2018-01-05 20:31:46 +0000] [5] [INFO] Starting gunicorn 19.7.1
explore_1   | [2018-01-05 20:31:46 +0000] [5] [INFO] Listening at: http://0.0.0.0:8080 (5)
explore_1   | [2018-01-05 20:31:46 +0000] [5] [INFO] Using worker: sync
explore_1   | [2018-01-05 20:31:46 +0000] [8] [INFO] Booting worker with pid: 8
explore_1   | [2018-01-05 20:31:46 +0000] [8] [ERROR] Exception in worker process
explore_1   | Traceback (most recent call last):
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/arbiter.py", line 578, in spawn_worker
explore_1   |     worker.init_process()
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 126, in init_process
explore_1   |     self.load_wsgi()
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/workers/base.py", line 135, in load_wsgi
explore_1   |     self.wsgi = self.app.wsgi()
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/app/base.py", line 67, in wsgi
explore_1   |     self.callable = self.load()
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 65, in load
explore_1   |     return self.load_wsgiapp()
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
explore_1   |     return util.import_app(self.app_uri)
explore_1   |   File "/usr/local/lib/python3.6/site-packages/gunicorn/util.py", line 352, in import_app
explore_1   |     __import__(module)
explore_1   | ModuleNotFoundError: No module named 'wsgi'
explore_1   | [2018-01-05 20:31:46 +0000] [8] [INFO] Worker exiting (pid: 8)
explore_1   | [2018-01-05 20:31:47 +0000] [5] [INFO] Shutting down: Master
explore_1   | [2018-01-05 20:31:47 +0000] [5] [INFO] Reason: Worker failed to boot.

3 个答案:

答案 0 :(得分:1)

您要求gunicorn在当前目录中运行文件名wsgi.py,或者在名为wsgi的模块中运行。后者可以只是一个名为wsgi/的目录,其中包含__init__.py文件(因此您需要wsgi/__init__.py

如果您的网络应用程序包含在名称不同的文件中,则需要将gunicorn命令从wsgi调整为其中的任何内容。

由于您似乎正在使用Docker来运行此操作,因此您可能还没有使用ADD中的Dockerfile命令将wsgi.py文件复制到您的文件中Docker容器。或者,您可能已经这样做了,但它与您运行gunicorn命令的目录位于不同的目录中。

答案 1 :(得分:1)

改变这个:

CMD gunicorn -w 3 -b 0.0.0.0:8080 wsgi --reload

到此:

CMD gunicorn -w 3 -b 0.0.0.0:8080 /full/path/to/wsgi --reload

其中/full/path/to/wsgi是您应用的绝对路径 - 我猜它是/usr/src/app/wsgi?)

答案 2 :(得分:1)

要更改为项目文件夹,可以使用命令-chdir
示例:

gunicorn -w 2 -b 0.0.0.0:8000 --chdir /code/myproject myproject.wsgi