Daniel Lyam Montross
Daniel Lyam Montross

Reputation: 249

mod_wsgi reports syntax error in pyramid module

I've just finished up installing mod_wsgi but I'm having problems starting my Pyramid application.

I'm using python 2.7, Apache 2.2.3, mod_wsgi 3.4 on CentOS 5.8

Here is my httpd.config file

WSGISocketPrefix run/wsgi

<VirtualHost *:80>
 ServerName  myapp.domain.com
 ServerAlias myapp
 WSGIApplicationGroup %{GLOBAL}
 WSGIPassAuthorization On
 WSGIDaemonProcess pyramid user=apache group=apache  processes=1 threads=4 \
   python-path=/var/wsgi_sites/site-packages
 WSGIScriptAlias / /var/wsgi_sites/myapp/apache.wsgi

<Directory /var/wsgi_sites/myapp>
  WSGIProcessGroup pyramid
  Order allow,deny
  Allow from all
</Directory>

  LogLevel debug
  ErrorLog /var/log/httpd/myapp_error
</VirtualHost>

I have given Apache ownership of site-package, python-eggs and myapp folders.

Module which I'm using to create WSGI application appache.wsgi contains the following code

import os
os.environ['PYTHON_EGG_CACHE'] = '/var/wsgi_sites/python-eggs'

from pyramid.paster import get_app
application = get_app('/var/wsgi_sites/myapp/development.ini','main')

When I restart Apache and try to access application I get the following error

mod_wsgi (pid=14842, process='pyramid', application=''): Loading WSGI script '/var/wsgi_sites/myapp/apache.wsgi'.
mod_wsgi (pid=14842): Target WSGI script '/var/wsgi_sites/myapp/apache.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=14842): Exception occurred processing WSGI script '/var/wsgi_sites/myapp/apache.wsgi'.
Traceback (most recent call last):
File "/var/wsgi_sites/myapp/apache.wsgi", line 4, in ?
from pyramid.paster import get_app
File "/var/wsgi_sites/site-packages/pyramid-1.3.2-py2.7.egg/pyramid/__init__.py", line 1, in ?
from pyramid.request import Request
File "/var/wsgi_sites/site-packages/pyramid-1.3.2-py2.7.egg/pyramid/request.py", line 
class Request(BaseRequest, DeprecatedRequestMethodsMixin, URLMethodsMixin,
    ^
SyntaxError: invalid syntax

I tried looking at the request.py file but there are no syntax errors.

Upvotes: 1

Views: 504

Answers (2)

Guddu
Guddu

Reputation: 1588

I see two different wsgi files mentioned in the error

/var/wsgi_sites/project_name_api/apache.wsgi

and

/var/wsgi_sites/myapp/apache.wsgi

I cannot see any project_name path reference in the httpd.conf that you pasted.

You might want to start by reviewing that. If the problem persists then please post additional information to help you further.

Upvotes: 0

mechanical_meat
mechanical_meat

Reputation: 169494

Often when you get syntax errors the preceding line is the culprit. Looking at the Pyramid source we see that the preceding line is:

@implementer(IRequest)

This is a class-decorator. Class-decorators were added to Python in version 2.6. The default version of Python on CentOS 5.8 is 2.4.

Your solution is to either:
1. use an OS with a more recent version of Python, or
2. ensure that your Pyramid application uses version 2.7. This involves installing Python 2.7 in addition to the system's default Python installation which is used by other applications and must be left alone.

If you choose to install 2.7 you will do something like the following:

$ wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2
$ tar xf Python-2.7.3.tar.bz2
$ cd Python-2.7.3
$ ./configure --prefix=/usr/local
$ make && make altinstall

Upvotes: 5

Related Questions