Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

django serving: wsgi.py? 'cannot be loaded as Python module'

Tags:

python

django

Trying to serve a django admin site to no avail. A 500 internal server error occurs when requested. The error claims the wsgi.py cannot be loaded as Python module. Below see the internal server error and the relevant files.

Possibly related: At first was trying with a local build of python. Another system admin tried this loca build of python and it would not execute. This local build is only working for my user. I say this is possibly related but have tried with the system python too.

500 internal server error when the site is requested. Here is the server error log:

[error] [client 208.120.168.168] mod_wsgi (pid=20239): Target WSGI script '/home/andrew/public_html/7DigAdmin/wsgi.py' cannot be loaded as Python module.
[error] [client 208.120.168.168] mod_wsgi (pid=20239): Exception occurred processing WSGI script '/home/andrew/public_html/7DigAdmin/wsgi.py'.
[error] Traceback (most recent call last):
[error] File "/home/andrew/public_html/7DigAdmin/wsgi.py", line 5, in ?
[error] import os
[error] ImportError: No module named os

wsgi.py:

import os

os.environ.setdefault("DJANGO_SETTINGS_MODULE", "/home/andrew/SCTN_7DigAdmin/SCTN_7DigAdmin/SCTN_7DigAdmin.settings")

from django.core.wsgi import get_wsgi_application
application = get_wsgi_application()

wsgi.conf:

LoadModule wsgi_module modules/mod_wsgi.so

WSGIPythonHome /usr/local/bin/python2.7

httpd.conf:

WSGIScriptAlias /7dadmin /home/andrew/public_html/7DigAdmin/wsgi.py
  <Directory /home/andrew/public_html/7DigAdmin>
     Order allow,deny
     Allow from all
  </Directory>
like image 749
Andrew Madden Avatar asked Nov 13 '22 12:11

Andrew Madden


1 Answers

I imagine the error is because you are setting WSGIPythonHome to the Python bin directory. As the mod_wsgi documentation explains, it's supposed to be pointing to the library directory. Your error is because the normal library files, such as the os module, are not in that bin directory.

However, that directive should only be used where the library files are in an unexpected location, which doesn't seem to be the case for you. You should remove that directive completely.

like image 196
Daniel Roseman Avatar answered Nov 15 '22 06:11

Daniel Roseman