Mod_wsgi python cannot import from standard library

I created two python environments with virtualenv: /usr/local/pythonenv/BASELINE and /usr/local/pythonenv/django1 . Both were created with -no-site packages. I installed django in a django1 environment using easy_install.

This line is installed in my wsgi.conf file to install the Python interpreter:

 WSGIPythonHome /usr/local/pythonenv/BASELINE 

My django.wsgi file starts as:

 import site site.addsitedir('/usr/local/pythonenv/django1/lib/python2.7/site-packages') import os import sys 

But when I try to visit my site, I get 500 errors, and httpd / error_log contains:

 [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 

I am lost as to why the Python interpreter cannot import its own standard library. I don’t even know how to check if httpd really uses the interpreter in / usr / local / pythonenv / BASELINE, so this will be a good start.

Edit: unrelated, but I was pretty torn apart if I should post this here or in ServerFault. Council on this front appreciated.

Edit: This way, I was able to get some debugging information thanks to http://code.google.com/p/modwsgi/wiki/DebuggingTechniques . I replaced django.wsgi script with

 import sys def application(environ, start_response): status = '200 OK' output = 'Hello World!' print >> environ['wsgi.errors'], sys.path print >> environ['wsgi.errors'], sys.prefix print >> environ['wsgi.errors'], sys.executable response_headers = [('Content-type', 'text/plain'), ('Content-Length', str(len(output)))] start_response(status, response_headers) return [output] 

This puts the Python interpreter information in / var / log / httpd / error _log. Error output:

 [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 

So sys.path and sys.executable point to my problem. For some reason, sys.path uses some lib files that don't exist (BASELINE doesn't even contain the lib64 directory, and it was created with Python2.7), and sys.executable shows that mod_wsgi still works by default / usr / bin / python, not the interpreter in / usr / local / pythonenv / BASELINE / bin.

I don’t know why this is so, but at least I know a little more.

EDIT: this is resolved, but Django still displays "Python Executable: / usr / bin / python", although it should be (and as far as I can tell, this is starting from Python version 2.7.2) using / USR / local / bin / python. This is normal?

+6
source share
1 answer

Your mod_wsgi is most likely not compiled with Python 2.7. You cannot use virtualenv for one version of Python with mod_wsgi compiled with another version of Python.

Read from:

http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Shared_Library

and perform the checks in this document.

+4
source

Source: https://habr.com/ru/post/899256/


All Articles