Note that there are some explanatory texts on larger screens.

plurals
  1. POmod_wsgi python can't import from standard library
    primarykey
    data
    text
    <p>I have created two python environments with virtualenv: <code>/usr/local/pythonenv/BASELINE</code> and <code>/usr/local/pythonenv/django1</code>. Both were created with --no-site-packages. I installed django to the django1 environment with easy_install.</p> <p>My wsgi.conf file has this line to set the Python interpreter:</p> <pre><code>WSGIPythonHome /usr/local/pythonenv/BASELINE </code></pre> <p>My django.wsgi file starts like:</p> <pre><code>import site site.addsitedir('/usr/local/pythonenv/django1/lib/python2.7/site-packages') import os import sys </code></pre> <p>But when I try to visit my site, I get a 500 Error, and httpd/error_log contains:</p> <pre><code>[error] Traceback (most recent call last): [error] File "/service/usr/local/django_apps/apache/django.wsgi", line 1, in ? [error] import site [error] ImportError: No module named site </code></pre> <p>I am lost as to why the Python interpreter can't import its own standard library. I'm not even sure how to check if httpd is even using the interpreter in /usr/local/pythonenv/BASELINE, so that would be a good start.</p> <p>Edit: Unrelated but I was quite torn on whether I should post this here or to ServerFault. Advice on that front appreciated.</p> <p>Edit: So I was able to get some debug information thanks to <a href="http://code.google.com/p/modwsgi/wiki/DebuggingTechniques" rel="nofollow">http://code.google.com/p/modwsgi/wiki/DebuggingTechniques</a>. I changed my django.wsgi script to contain </p> <pre><code>import sys def application(environ, start_response): status = '200 OK' output = 'Hello World!' print &gt;&gt; environ['wsgi.errors'], sys.path print &gt;&gt; environ['wsgi.errors'], sys.prefix print &gt;&gt; environ['wsgi.errors'], sys.executable response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] </code></pre> <p>This put the Python interpreter information in /var/log/httpd/error_log. The error output:</p> <pre><code>[error] ['/usr/local/pythonenv/BASELINE/lib64/python24.zip', '/usr/local/pythonenv/BASELINE/lib64/python2.4/', '/usr/local/pythonenv/BASELINE/lib64/python2.4/plat-linux2', '/usr/local/pythonenv/BASELINE/lib64/python2.4/lib-tk', '/usr/local/pythonenv/BASELINE/lib64/python2.4/lib-dynload'] [error] /usr/local/pythonenv/BASELINE [error] /usr/bin/python </code></pre> <p>So sys.path and sys.executable point to my problem. For some reason sys.path is using some lib files that do not exist (BASELINE does not even contain a lib64 directory, and it was created with Python2.7), and sys.executable shows that mod_wsgi is still running the default /usr/bin/python interpreter, not the interpreter in /usr/local/pythonenv/BASELINE/bin.</p> <p>Not sure why this is the case, but at least I know a bit more now.</p> <p>EDIT: This is solved, but Django still lists "Python Executable: /usr/bin/python" even though it should be (and as far as I can tell, it is, since Python Version: 2.7.2) using /usr/local/bin/python. Is this normal?</p>
    singulars
    1. This table or related slice is empty.
    plurals
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
    1. This table or related slice is empty.
 

Querying!

 
Guidance

SQuiL has stopped working due to an internal error.

If you are curious you may find further information in the browser console, which is accessible through the devtools (F12).

Reload