【发布时间】:2018-11-07 11:33:47
【问题描述】:
我正在关注tutorial 在 AWS EC2 中设置 Django-gunicorn-nginx 服务器。安装所有依赖项并在 wsgi.py 中进行如下更改后
import os, sys
# add the hellodjango project path into the sys.path
sys.path.append('/home/ubuntu/project/ToDo-application/')
# add the virtualenv site-packages path to the sys.path
sys.path.append('/home/ubuntu/.local/lib/python3.6/site-packages')
# poiting to the project settings
os.environ.setdefault("DJANGO_SETTINGS_MODULE", "todo_app.settings")
from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()
我运行gunicorn todo_app.wsgi 并得到以下错误:
ubuntu@ip-172-31-61-163:~/project/ToDo-application$ gunicorn todo_app.wsgi
[2018-11-07 11:25:35 +0000] [8211] [INFO] Starting gunicorn 19.7.1
[2018-11-07 11:25:35 +0000] [8211] [INFO] Listening at: http://127.0.0.1:8000 (8211)
[2018-11-07 11:25:35 +0000] [8211] [INFO] Using worker: sync
[2018-11-07 11:25:35 +0000] [8215] [INFO] Booting worker with pid: 8215
[2018-11-07 11:25:35 +0000] [8215] [ERROR] Exception in worker process
Traceback (most recent call last):
File "/usr/lib/python2.7/dist-packages/gunicorn/arbiter.py", line 578, 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 135, 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 377, in import_app
__import__(module)
File "/home/ubuntu/urbanpiper/ToDo-application/todo_app/wsgi.py", line 20, in <module>
from django.core.wsgi import get_wsgi_application
File "/home/ubuntu/.local/lib/python3.6/site-packages/django/__init__.py", line 1, in <module>
from django.utils.version import get_version
File "/home/ubuntu/.local/lib/python3.6/site-packages/django/utils/version.py", line 71, in <module>
@functools.lru_cache()
AttributeError: 'module' object has no attribute 'lru_cache'
这是因为 gunicorn 具有 python2 依赖项而 Django 在 python3 上?我尝试卸载 gunicorn 并再次尝试,但没有成功。
【问题讨论】:
-
你是如何安装 gunicorn 的?您需要为 Python 3 而不是 2 安装它。
-
所以我使用
pip3 install gunicorn安装它,但我无法使用gunicorn app_name.wsgi运行它,尝试python3 -m gunicorn todo_app.wsgi。我得到了/usr/bin/python3: No module named gunicorn.__main__; 'gunicorn' is a package and cannot be directly executed。这就是我使用sudo apt-get install gunicorn安装它的原因
标签: django amazon-web-services amazon-ec2 gunicorn