lau*_*kok 11 python django virtualenv gunicorn
我已经gunicorn安装在我的虚拟环境中:
$ pip install gunicorn
Collecting gunicorn
Using cached gunicorn-19.7.1-py2.py3-none-any.whl
Installing collected packages: gunicorn
Successfully installed gunicorn-19.7.1
Run Code Online (Sandbox Code Playgroud)
但是当我尝试用它运行我的应用程序时:
$ gunicorn helloapp.wsgi
[2017-05-18 22:42:36 +0000] [1963] [INFO] Starting gunicorn 19.6.0
[2017-05-18 22:42:36 +0000] [1963] [INFO] Listening at: http://127.0.0.1:8000 (1963)
[2017-05-18 22:42:36 +0000] [1963] [INFO] Using worker: sync
[2017-05-18 22:42:36 +0000] [1967] [INFO] Booting worker with pid: 1967
[2017-05-18 22:42:36 +0000] [1967] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 557, in spawn_worker
worker.init_process()
File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 126, in init_process
self.load_wsgi()
File "/usr/lib/python2.7/dist-packages/gunicorn/workers/base.py", line 136, in load_wsgi
self.wsgi = self.app.wsgi()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/base.py", line 67, in wsgi
self.callable = self.load()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 65, in load
return self.load_wsgiapp()
File "/usr/lib/python2.7/dist-packages/gunicorn/app/wsgiapp.py", line 52, in load_wsgiapp
return util.import_app(self.app_uri)
File "/usr/lib/python2.7/dist-packages/gunicorn/util.py", line 384, in import_app
__import__(module)
File "/var/www/html/django-project/helloapp/helloapp/wsgi.py", line 12, in <module>
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
[2017-05-18 22:42:36 +0000] [1967] [INFO] Worker exiting (pid: 1967)
[2017-05-18 22:42:36 +0000] [1963] [INFO] Shutting down: Master
[2017-05-18 22:42:36 +0000] [1963] [INFO] Reason: Worker failed to boot.
Run Code Online (Sandbox Code Playgroud)
我做错了什么?
有任何想法吗?
这是我的要求.txt:
appdirs==1.4.3
Django==1.11.1
gunicorn==19.7.1
packaging==16.8
pyparsing==2.2.0
pytz==2017.2
six==1.10.0
Run Code Online (Sandbox Code Playgroud)
编辑:
(env) xxx@xxx-desktop:/var/www/html/django-project/helloapp$ which gunicorn
/var/www/html/django-project/helloapp/env/bin/gunicorn
(env) xxx@xxx-desktop:/var/www/html/django-project/helloapp$ which pip
/var/www/html/django-project/helloapp/env/bin/pip
Run Code Online (Sandbox Code Playgroud)
小智 12
对于这个特定问题来说,情况可能并非如此,但是我遇到了类似的问题,并且是由谷歌引导到这里的。所以我把这个答案放在这里,希望对其他人有用。
对我来说,问题是gunicorn 是由globally installed package不是安装在虚拟环境中的那个运行的。要确定您是否属于这种情况,只需运行which gunicorn并检查它是否来自您的 virtualenv bin 目录。如果它不是来自您的虚拟环境 bin 目录,请按照以下步骤操作:
deactivate envpip uninstall gunicornworkon env现在,gunicorn 应该可以按预期工作。
我有同样的问题,我通过删除与系统包管理器(apt-get等)一起安装的gunicorn来解决它。
apt-get将 Gunicorn 安装到python2 的站点包并pip安装Django到python3 的站点包。所以 Gunicorn 和 Django 不在同一个 site-packages 目录中。所以gunicorn找不到django。将 Gunicorn 和 Django 安装在同一包目录中应该可以解决问题。
小智 5
在 中/etc/systemd/system/gunicorn.service,确保您的工作目录指向您的应用程序目录。
[Unit]
Description=gunicorn daemon
After=network.target
[Service]
User=sammy
Group=www-data
WorkingDirectory=/home/sammy/myproject
ExecStart=/home/sammy/myproject/myprojectenv/bin/gunicorn --access-logfile - --workers 3 --bind unix:/home/sammy/myproject/myproject.sock myproject.wsgi:application
Run Code Online (Sandbox Code Playgroud)
你实际上应该按如下方式运行它:
gunicorn helloapp.wsgi:application
Run Code Online (Sandbox Code Playgroud)
gunicorn [OPTIONS] APP_MODULE
APP_MODULE图案在哪里$(MODULE_NAME):$(VARIABLE_NAME)
| 归档时间: |
|
| 查看次数: |
10290 次 |
| 最近记录: |