[英]mod_wsgi python can't import from standard library
I have created two python environments with virtualenv: /usr/local/pythonenv/BASELINE
and /usr/local/pythonenv/django1
. 我用virtualenv创建了两个python环境: /usr/local/pythonenv/BASELINE
和/usr/local/pythonenv/django1
。 Both were created with --no-site-packages. 两者都是使用--no-site-packages创建的。 I installed django to the django1 environment with easy_install. 我使用easy_install将django安装到django1环境中。
My wsgi.conf file has this line to set the Python interpreter: 我的wsgi.conf文件有这一行来设置Python解释器:
WSGIPythonHome /usr/local/pythonenv/BASELINE
My django.wsgi file starts like: 我的django.wsgi文件开头像:
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 a 500 Error, and httpd/error_log contains: 但是当我尝试访问我的网站时,我得到500错误,httpd / error_log包含:
[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 can't import its own standard library. 我很遗憾为什么Python解释器无法导入自己的标准库。 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. 我甚至不确定如何检查httpd是否甚至使用/ usr / local / pythonenv / BASELINE中的解释器,这将是一个良好的开端。
Edit: Unrelated but I was quite torn on whether I should post this here or to ServerFault. 编辑:不相关,但我是否应该在这里或ServerFault发布这个很疯狂。 Advice on that front appreciated. 对这方面的建议表示赞赏。
Edit: So I was able to get some debug information thanks to http://code.google.com/p/modwsgi/wiki/DebuggingTechniques . 编辑:所以我能够通过http://code.google.com/p/modwsgi/wiki/DebuggingTechniques获得一些调试信息。 I changed my django.wsgi script to contain 我改变了我的django.wsgi脚本来包含
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 put the Python interpreter information in /var/log/httpd/error_log. 这将Python解释器信息放在/ var / log / httpd / error_log中。 The 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. 所以sys.path和sys.executable指向我的问题。 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. 由于某种原因,sys.path使用了一些不存在的lib文件(BASELINE甚至不包含lib64目录,它是用Python2.7创建的),而sys.executable显示mod_wsgi仍然运行默认的/ usr / bin / python解释器,而不是/ usr / local / pythonenv / BASELINE / bin中的解释器。
Not sure why this is the case, but at least I know a bit more now. 不知道为什么会这样,但至少我现在知道的更多了。
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. 编辑:这已经解决了,但Django仍然列出“Python可执行文件:/ usr / bin / python”,即使它应该是(并且据我所知,它是,因为Python版本:2.7.2)使用/ usr / local / bin目录/蟒蛇。 Is this normal? 这是正常的吗?
Your mod_wsgi is likely not compiled against Python 2.7. 你的mod_wsgi很可能不是针对Python 2.7编译的。 You cannot use a virtualenv for one Python version with mod_wsgi compiled against a different Python version. 你不能将virtualenv用于一个Python版本,而mod_wsgi是针对不同的Python版本编译的。
Read from: 阅读:
http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Shared_Library http://code.google.com/p/modwsgi/wiki/CheckingYourInstallation#Python_Shared_Library
and do checks in that document. 并检查该文件。
声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.