1

I am getting "Internal Server Error" when I try to access the django website. I am using Django 1.8, Python 2.7.10, centos 6.5 and apache.

In apache log I am getting the following error:

mod_wsgi (pid=23866): Target WSGI script '/abc/abc/abc/wsgi.py' cannot be loaded as Python module.
[Mon May 25 14:40:47 2015] [error] [client xyz] mod_wsgi (pid=23866): Exception occurred processing WSGI script '/abc/abc/abc/wsgi.py'.
[Mon May 25 14:40:47 2015] [error] [client xyz] Traceback (most recent call last):
[Mon May 25 14:40:47 2015] [error] [client xyz]   File "/abc/abc/abc/wsgi.py", line 12, in <module>
[Mon May 25 14:40:47 2015] [error] [client xyz]     from django.core.wsgi import get_wsgi_application
[Mon May 25 14:40:47 2015] [error] [client xyz]   File "/abc/lib/python2.7/site-packages/django/__init__.py", line 1, in <module>
[Mon May 25 14:40:47 2015] [error] [client xyz]     from django.utils.version import get_version
[Mon May 25 14:40:47 2015] [error] [client xyz]   File "/abc/lib/python2.7/site-packages/django/utils/version.py", line 7, in <module>
[Mon May 25 14:40:47 2015] [error] [client xyz]     from django.utils.lru_cache import lru_cache
[Mon May 25 14:40:47 2015] [error] [client xyz]   File "/abc/lib/python2.7/site-packages/django/utils/lru_cache.py", line 28
[Mon May 25 14:40:47 2015] [error] [client xyz]      fasttypes = {int, str, frozenset, type(None)},
[Mon May 25 14:40:47 2015] [error] [client xyz]                      ^
[Mon May 25 14:40:47 2015] [error] [client xyz]  SyntaxError: invalid syntax

Thanks

Sid Shukla
  • 990
  • 1
  • 8
  • 33
ak111in
  • 107
  • 2
  • 11

2 Answers2

7

Although you say you are running Python 2.7, this error indicates that in fact you are using 2.6, as set literals were only introduced in 2.7.

The issue is that mod_wsgi is compiled against a specific Python version, which in your case is the one that comes with Centos 6.5. You will need to recompile it for 2.7, or find a version already compiled against that.

Daniel Roseman
  • 588,541
  • 66
  • 880
  • 895
  • ok thanks. Can you point me to some links on how to recompile mod_wsgi for 2.7. Also I followed tutorial at https://www.digitalocean.com/community/tutorials/how-to-set-up-python-2-7-6-and-3-3-3-on-centos-6-4 and can access python 2.7 with python2.7 but not sure why django is still taking 2.6 version. – ak111in May 25 '15 at 20:05
0

You need to start using virtualenv for your django project. Here's a nice tutorial. For a makeshift solution, you can just run django with python 2.7 by using python2.7 manage.py runserver. However, it's highly recommended to look into virtualenv. Makes life much easier.

With regards to making mod_wsgi use python 2.7, you need to recompile it. For that, just download the source and execute:

$ ./configure
$ make
$ sudo make install

They have a quick installation guide that you can access here.

Sid Shukla
  • 990
  • 1
  • 8
  • 33
  • Thanks tried making mod_wsgi but kept on getting one error after other and could not complete the make step, so moved to centos 7 which has python 2.7 already built in and it worked perfectly. – ak111in May 26 '15 at 09:46