如何从不是 django 项目文件夹的文件夹中 运行 gunicorn
How to run gunicorn from a folder that is not the django project folder
我 git 在我的主文件夹中克隆了一个项目,我们称它为 /home/telessaude
。所以项目根目录位于/home/telessaude/telessaude_branch_master
如果我在 Django 项目主文件夹 (/home/telessaude/telessaude_branch_master) 中并发出 gunicorn 命令,例如
gunicorn -w 2 -b 0.0.0.0:8000 telessaude.wsgi_dev:application --reload --timeout 900
gunicorn 启动并运行良好。但是......如果我尝试 运行 在上面的一个目录( /home/telessaude )上执行相同的命令,我会收到以下错误:
telessaude@ubuntu:~$ gunicorn -w 2 -b 0.0.0.0:8000 telessaude.wsgi_dev:application --reload --timeout 900
[2017-03-22 16:39:28 +0000] [10405] [INFO] Starting gunicorn 19.6.0
[2017-03-22 16:39:28 +0000] [10405] [INFO] Listening at: http://0.0.0.0:8000 (10405)
[2017-03-22 16:39:28 +0000] [10405] [INFO] Using worker: sync
[2017-03-22 16:39:28 +0000] [10410] [INFO] Booting worker with pid: 10410
[2017-03-22 16:39:28 +0000] [10410] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
ImportError: No module named telessaude.wsgi_dev
我也在我的主文件夹中尝试 运行ning gunicorn
gunicorn -w 2 -b 0.0.0.0:8000 telessaude_branch_master.telessaude.wsgi_dev:application --reload --timeout 900
和
gunicorn -w 2 -b 0.0.0.0:8000 /home/telessaude/telessaude_branch_master/telessaude.wsgi_dev:application --reload --timeout 900
但其中 none 也有效。有人可以告诉我如何解决这个问题吗?我需要从任何文件夹中 运行 gunicorn,因为我必须将它作为 "command" 参数添加到主管。
我没有使用虚拟环境。
您可以在执行命令之前使用 Gunicorn 的 chdir
标志更改到项目目录。
gunicorn -w 2 -b 0.0.0.0:8000 --chdir /home/telessaude/telessaude_branch_master telessaude.wsgi_dev:application --reload --timeout 900
您应该将您的 django 应用程序添加到 Python 路径。
在最新的gunicorn中,你可以试试这个:
如果django项目根路径为/usr/local/src/djangoapp/
.
settings.py
路径默认为 /usr/local/src/djangoapp/djangoapp/settings.py
。
gunicorn \
-c /usr/local/src/djangoapp/gunicorn_config.py \
--env DJANGO_SETTINGS_MODULE=djangoapp.settings \
--pythonpath '/usr/local/src/djangoapp' \
djangoapp.wsgi:application
- -c 配置文件路径
- --env你的django项目settings.py的模块路径
- --pythonpath 添加你的项目路径到Python Path settings.html#pythonpath
--env
和 --pythonpath
是必需的。
Relative Path also be fine!
我 git 在我的主文件夹中克隆了一个项目,我们称它为 /home/telessaude
。所以项目根目录位于/home/telessaude/telessaude_branch_master
如果我在 Django 项目主文件夹 (/home/telessaude/telessaude_branch_master) 中并发出 gunicorn 命令,例如
gunicorn -w 2 -b 0.0.0.0:8000 telessaude.wsgi_dev:application --reload --timeout 900
gunicorn 启动并运行良好。但是......如果我尝试 运行 在上面的一个目录( /home/telessaude )上执行相同的命令,我会收到以下错误:
telessaude@ubuntu:~$ gunicorn -w 2 -b 0.0.0.0:8000 telessaude.wsgi_dev:application --reload --timeout 900
[2017-03-22 16:39:28 +0000] [10405] [INFO] Starting gunicorn 19.6.0
[2017-03-22 16:39:28 +0000] [10405] [INFO] Listening at: http://0.0.0.0:8000 (10405)
[2017-03-22 16:39:28 +0000] [10405] [INFO] Using worker: sync
[2017-03-22 16:39:28 +0000] [10410] [INFO] Booting worker with pid: 10410
[2017-03-22 16:39:28 +0000] [10410] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/local/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/local/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/local/lib/python2.7/dist-packages/gunicorn/util.py", line 357, in import_app
__import__(module)
ImportError: No module named telessaude.wsgi_dev
我也在我的主文件夹中尝试 运行ning gunicorn
gunicorn -w 2 -b 0.0.0.0:8000 telessaude_branch_master.telessaude.wsgi_dev:application --reload --timeout 900
和
gunicorn -w 2 -b 0.0.0.0:8000 /home/telessaude/telessaude_branch_master/telessaude.wsgi_dev:application --reload --timeout 900
但其中 none 也有效。有人可以告诉我如何解决这个问题吗?我需要从任何文件夹中 运行 gunicorn,因为我必须将它作为 "command" 参数添加到主管。
我没有使用虚拟环境。
您可以在执行命令之前使用 Gunicorn 的 chdir
标志更改到项目目录。
gunicorn -w 2 -b 0.0.0.0:8000 --chdir /home/telessaude/telessaude_branch_master telessaude.wsgi_dev:application --reload --timeout 900
您应该将您的 django 应用程序添加到 Python 路径。
在最新的gunicorn中,你可以试试这个:
如果django项目根路径为/usr/local/src/djangoapp/
.
settings.py
路径默认为 /usr/local/src/djangoapp/djangoapp/settings.py
。
gunicorn \
-c /usr/local/src/djangoapp/gunicorn_config.py \
--env DJANGO_SETTINGS_MODULE=djangoapp.settings \
--pythonpath '/usr/local/src/djangoapp' \
djangoapp.wsgi:application
- -c 配置文件路径
- --env你的django项目settings.py的模块路径
- --pythonpath 添加你的项目路径到Python Path settings.html#pythonpath
--env
和 --pythonpath
是必需的。
Relative Path also be fine!