SyntaxError with VirtualEnv + mod-wsgi in Django

I am having problems using VirtualEnv

on my server Ubuntu 13.04

with mod-wsgi

.

Can anyone point out what the problem is?

Here is a traceback that results in the following syntax error:

[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

      

I have a flapsta.wsgi file configured like this:

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)

      

When I comment this line:

execfile(activate_env, dict(__file__=activate_env))

      

It doesn't activate anymore VirtualEnv

and I can load the site perfectly, but I can’t VirtualEnv

obviously use to host multiple sites with different dependencies.

Is this a known issue, or have I missed some of the configuration somewhere that someone might point out?

I am running:

Django 1.5.4
viritualenv 1.11.1
Apache2.2
Ubuntu 13.04
Python 2.7.4

      

Thanks in advance.

0


source to share


1 answer


You are trying to bash activate script in Python. You have to execute activate_this.py

Python script.



+3


source







All Articles