简体   繁体   中英

uwsgi and django - django uwsgi import is leaving virtualenv and crashing

Starting uwsgi from ini file crashes with the following stacktrace:

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/

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. 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

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)

Here is the uwsgi.ini file:

[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:

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()

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.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM