uwsgi和django - django uwsgi导入将离开virtualenv并崩溃。

时间:2022-10-30 19:21:32

Starting uwsgi from ini file crashes with the following stacktrace:

从ini文件启动uwsgi,与以下堆栈跟踪一起崩溃:

Traceback (most recent call last):                                                                                                                                                                                                                 
  File "/var/www/vhosts/x/projectX/wsgi.py", line 18, in <module>                                                                                                                                                                                  
    from django.core.wsgi import get_wsgi_application                                                                                                                                                                                              
  File "/var/www/vhosts/x/virtenv/local/lib/python2.7/site-packages/django/core/wsgi.py", line 1, in <module>                                                                                                                                      
    from django.core.handlers.wsgi import WSGIHandler                                                                                                                                                                                              
  File "/var/www/vhosts/x/virtenv/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 4, in <module>                                                                                                                             
    import logging                                                                                                                                                                                                                                 
  File "/usr/lib64/python2.7/logging/__init__.py", line 26, in <module>                                                                                                                                                                            
    import sys, os, time, cStringIO, traceback, warnings, weakref                                                                                                                                                                                  
ImportError: No module named time   

The Path /var/www/vhosts/x/virtenv/ is the correct virtualenv and it is using python 2.7 as expected. but for some reason, when importing "logging", it jumps to /usr/lib64/

路径/var/www/vhosts/x/virtenv/是正确的virtualenv,它按照预期使用了python 2.7。但是由于某些原因,当导入“日志记录”时,它会跳转到/usr/lib64/

2 more things to note here:

这里还有两点需要注意:

  1. The virtualenv is setup using the -p command (manually specifying /usr/bin/python2.7 as python version) and using --no-site-packages
  2. virtualenv使用-p命令(手工指定/usr/bin/python2.7作为python版本)进行设置,并使用—无站点包
  3. We have the almost identical uwsgi.ini file working with another django app (no problems there). Only difference seems to be that this projectX is running Django 1.6.1 and the other project is running Django 1.5
  4. 我们有几乎相同的uwsgi。ini文件与另一个django应用程序一起工作(没有问题)。唯一的区别似乎是这个项目运行的是Django 1.6.1,而另一个项目运行的是Django 1.5

The strangest thing is, if I try to execute the code from the wsgi.py file manually, it works perfectly fine. (I source the virtualenv, start the python command line and copy the wsgi.py's commands there)

最奇怪的是,如果我尝试执行来自wsgi的代码。py文件手动操作,效果非常好。(我为virtualenv提供源代码,启动python命令行并复制wsgi。py的命令)

Here is the uwsgi.ini file:

这是uwsgi。ini文件:

[uwsgi]
# variables
projectname = projectX
projectdomain = x.mydomain.com
base = /var/www/vhosts/x

# config
socket = 127.0.0.1:8989
chdir = %(base)
wsgi-file = %(base)/%(projectname)/wsgi.py
master = true
pidfile = /tmp/%(projectname)-master.pid
vacuum = true

max-requests = 5000
processes = 10
#harakiri = 20
uid = 109
gid = 113

callable = projectX

env = DJANGO_SETTINGS_MODULE=settings
home = %(base)/virtenv
touch-reload = %(base)
py-autoreload = 3

#daemonize = /var/log/x/uwsgi.log
virtualenv = %(base)/virtenv
pythonpath = %(base)/virtenv/lib/python2.7
pythonpath = %(base)
pythonpath = %(base)/%(projectname)

The wsgi.py file:

wsgi。py文件:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "projectX.settings")

from django.core.wsgi import get_wsgi_application    # <-- this is line 18
application = get_wsgi_application()

1 个解决方案

#1


1  

Resolved by changing

通过改变来解决

env = DJANGO_SETTINGS_MODULE=settings

to

env = DJANGO_SETTINGS_MODULE=projectX.settings

Still if any1 knows why this works on django 1.5 and not on 1.6.1, I would be very interested.

不过,如果any1知道为什么它适用于django 1.5而不适用于1.6.1,我还是会非常感兴趣。

#1


1  

Resolved by changing

通过改变来解决

env = DJANGO_SETTINGS_MODULE=settings

to

env = DJANGO_SETTINGS_MODULE=projectX.settings

Still if any1 knows why this works on django 1.5 and not on 1.6.1, I would be very interested.

不过,如果any1知道为什么它适用于django 1.5而不适用于1.6.1,我还是会非常感兴趣。