gpt4 book ai didi

django - uwsgi + nginx + Django : ImportError: No module named django. core.wsgi

转载 作者:行者123 更新时间:2023-12-02 11:50:21 25 4
gpt4 key购买 nike

我正在尝试使用 nginx + uwsgi 部署 Django 应用程序。我创建了一个虚拟环境(virtualenv),并在虚拟环境中安装了 uwsgi 和 Django(即虚拟环境的本地)。我没有全局 Django 和 uwsgi。当我运行 uwsgi --ini project.ini 时,出现“ImportError:没有名为 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,所以我没有再放置它们。这是我的项目.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

我该如何解决这个问题?我已经被这个问题困住了一天了。任何想法都将不胜感激。提前致谢!

最佳答案

你的模块指向你的项目,难道不应该指向你的项目主应用程序,这样它就可以找到 wsgi 文件吗?

所以我的 INI 文件看起来像这样。

在我的特定情况下,我使用虚拟环境 django 1.7 和 uwsgi。

vhost = true
plugins = python
socket = /tmp/noobmusic.sock
master = true
enable-threads = true
processes = 2
wsgi-file = /home/myname/webapps/music/music/music/wsgi.py
virtualenv = /home/myname/webapps/music/musicenv/
chdir = /home/myname/webapps/music/music/

这是我设置过 uwsgi 的唯一网站,因为我通常使用 mod-wsgi,但不幸的是不记得所有步骤。

关于django - uwsgi + nginx + Django : ImportError: No module named django. core.wsgi,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/28296419/

25 4 0