【发布时间】:2015-04-02 12:02:25
【问题描述】:
我正在尝试使用 nginx + uwsgi 部署 Django 应用程序。 我创建了一个虚拟环境(virtualenv),并在虚拟环境中安装了 uwsgi 和 Django(即虚拟环境的本地)。我没有全局 Django 和 uwsgi。当我运行 uwsgi --ini project.ini 时,出现“ImportError: No module named django.core.wsgi”异常:
from django.core.wsgi import get_wsgi_application
ImportError: No module named django.core.wsgi
unable to load app 0 (mountpoint='') (callable not found or import error)
*** no app loaded. going in full dynamic mode ***
*** uWSGI is running in multiple interpreter mode ***
spawned uWSGI master process (pid: 5987)
spawned uWSGI worker 1 (pid: 5988, cores: 1)
spawned uWSGI worker 2 (pid: 5989, cores: 1)
spawned uWSGI worker 3 (pid: 5990, cores: 1)
spawned uWSGI worker 4 (pid: 5991, cores: 1)
根据我的搜索,如果您使用的是 Django1.5 或更低版本,建议将 env 和 pythonpath 变量放在 ini 中。但是,我使用的是 Django 1.7,所以我不再放置它们。这是我的 project.ini:
#project.ini file
[uwsgi]
# Django-related settings
# the base directory (full path)
chdir = /root/virtualenv/project
# Django wsgi file
module = project.wsgi:application
# the virtualenv (full path)
home = /root/virtualenv
# process-related settings
# master
master = true
# maximum number of worker processes
processes = 4
# the socket (use the full path to be safe
socket = /root/virtualenv/project/project.sock
# ... with appropriate permissions - may be needed
chmod-socket = 666
chown-socket = root:root
# clear environment on exit
vacuum = true
# other config options
uid = root
gid = root
processes = 4
daemonize = /var/log/uwsgi/project.log
no-site = True
我将如何解决这个问题?我已经坚持了一天。 任何想法都非常感谢。 提前致谢!
【问题讨论】:
-
但是你是如何运行 uwsgi 的?您通常只需要在运行之前激活 virtualenv。
-
这是我的问题;如何运行uwsgi...我确实激活了虚拟环境然后运行uwsgi。但如前所述,我得到了上面的错误
-
但是当你遇到这个错误时你做了什么?请显示您输入的命令的确切顺序。
-
1.) 安装 python2.7 (带有 pip 和 virtualenv) 2.) virtualenv 3.) source bin/activate 4.) 安装 Django 5. 安装 uWSGI 6.) 修改 project.wsgi 7. ) 运行 uwsgi --ini project.ini