在Django中使用VirtualEnv + mod-wsgi的SyntaxError



我在mod-wsgi的生产Ubuntu 13.04服务器上使用VirtualEnv有问题。

谁能指出问题是什么?

下面是我得到以下语法错误的回溯:

[Mon Jul 14 14:37:09 2014] [error] [client 70.180.246.22] mod_wsgi (pid=14292): Target WSGI script '/home/aaron/public_html/flapsta.com/flapsta/flapsta/flapsta.wsgi' cannot be loaded as Python module.
[Mon Jul 14 14:37:09 2014] [error] [client 70.180.246.22] mod_wsgi (pid=14292): Exception occurred processing WSGI script '/home/aaron/public_html/flapsta.com/flapsta/flapsta/flapsta.wsgi'.
[Mon Jul 14 14:37:09 2014] [error] [client 70.180.246.22] Traceback (most recent call last):
[Mon Jul 14 14:37:09 2014] [error] [client 70.180.246.22]   File "/home/aaron/public_html/flapsta.com/flapsta/flapsta/flapsta.wsgi", line 16, in <module>
[Mon Jul 14 14:37:09 2014] [error] [client 70.180.246.22]     execfile(activate_env, dict(__file__=activate_env))
[Mon Jul 14 14:37:09 2014] [error] [client 70.180.246.22]   File "/home/.virtualenvs/flapsta/bin/activate", line 4
[Mon Jul 14 14:37:09 2014] [error] [client 70.180.246.22]     deactivate () {
[Mon Jul 14 14:37:09 2014] [error] [client 70.180.246.22]                   ^
[Mon Jul 14 14:37:09 2014] [error] [client 70.180.246.22] SyntaxError: invalid syntax

我有我的flapsta。Wsgi文件设置如下:

import os
import sys
import site
# Add the site-packages of the chosen virtualenv to work with
site.addsitedir('/home/.virtualenvs/flapsta/lib/python2.7/site-packages')
# Add the app directories to the PYTHONPATH
sys.path.append('/home/aaron/public_html/flapsta.com')
sys.path.append('/home/aaron/public_html/flapsta.com/flapsta')
os.environ['DJANGO_SETTINGS_MODULE'] = 'flapsta.settings'
# Activate the virtualenv
activate_env=os.path.expanduser('/home/.virtualenvs/flapsta/bin/activate')
execfile(activate_env, dict(__file__=activate_env))
import django.core.handlers.wsgi
_application = django.core.handlers.wsgi.WSGIHandler()
def application(environ, start_response):
    # DB
    # .... envirtonment variables ....
    return _application(environ, start_response)

当我注释掉这一行时:

execfile(activate_env, dict(__file__=activate_env))

它不再激活virtualenv,我可以很好地加载站点,但我不能使用virtualenv明显地托管多个具有不同依赖关系的站点。

这是一个已知的问题,还是我错过了一个配置的地方,有人可以帮助指出?

我运行:

Django 1.5.4
viritualenv 1.11.1
Apache2.2
Ubuntu 13.04
Python 2.7.4

您正在尝试用Python执行bash激活脚本。您应该执行activate_this.py Python脚本。

最新更新