【发布时间】:2016-04-10 04:02:40
【问题描述】:
有很多类似的问题,但我已经解决了所有问题,但没有一个能解决我的问题。我在 Centos 6 中配置了 httpd 以使用 mod_wsgi 运行 django。由于 dist python 是 2.6 版,我编译并安装了 python2.7(UCS2,shared-lib)。在/var/www/uatenv下创建了一个带有virtualenv -p /usr/local/bin/python2.7的virtulenv
<VirtualHost *:8080>
Alias /static/ /var/www/uatenv/my_app/static/
WSGIDaemonProcess rbuat python-path=/var/www/my_app/core:/var/www/uatenv/lib/python2.7/site-packages
WSGIProcessGroup rbuat
WSGIScriptAlias / /var/www/uatenv/my_app/core/wsgi.py
</VirtualHost>
但是服务器抛出了 500 错误并且它使用了不同版本的 python
为了获得更多详细信息,我在wsgi.py 中添加了几行如下
import sys
print sys.version
print sys.executable
print sys.maxunicode
print sys.prefix
重新启动服务器后,从日志中获取了以下详细信息
[notice] Apache/2.2.15 (Unix) DAV/2 mod_wsgi/4.4.21 Python/2.7.10 mod_perl/2.0.4 Perl/v5.10.1 configured -- resuming normal operations
[error] 2.7.10 (default, Dec 29 2015, 07:15:09)
[error] [GCC 4.4.7 20120313 (Red Hat 4.4.7-16)]
[error] /usr/bin/python
[error] 1114111
[error] /usr/local
[error] [client 10.3.35.113] mod_wsgi (pid=7118): Target WSGI script '/var/www/uatenv/my_app/core/wsgi.py' cannot be loaded as Python module.
[error] [client 10.3.35.113] mod_wsgi (pid=7118): Exception occurred processing WSGI script '/var/www/uatenv/my_app/core/wsgi.py'.
[error] [client 10.3.35.113] Traceback (most recent call last):
[error] [client 10.3.35.113] File "/var/www/uatenv/my_app/core/wsgi.py", line 17, in <module>
[error] [client 10.3.35.113] from django.core.wsgi import get_wsgi_application
[error] [client 10.3.35.113] File "/var/www/uatenv/lib/python2.7/site-packages/django/__init__.py", line 1, in <module>
[error] [client 10.3.35.113] from django.utils.version import get_version
[error] [client 10.3.35.113] File "/var/www/uatenv/lib/python2.7/site-packages/django/utils/version.py", line 5, in <module>
[error] [client 10.3.35.113] import subprocess
[error] [client 10.3.35.113] File "/usr/local/lib/python2.7/subprocess.py", line 430, in <module>
[error] [client 10.3.35.113] import pickle
[error] [client 10.3.35.113] File "/usr/local/lib/python2.7/pickle.py", line 34, in <module>
[error] [client 10.3.35.113] import struct
[error] [client 10.3.35.113] File "/usr/local/lib/python2.7/struct.py", line 1, in <module>
[error] [client 10.3.35.113] from _struct import *
[error] [client 10.3.35.113] ImportError: /usr/local/lib/python2.7/lib-dynload/_struct.so: undefined symbol: PyUnicodeUCS2_AsEncodedString
所以从日志中它正在使用 /usr/bin/python 并显示 2.7 但是当我运行时
# /usr/bin/python
Python 2.6.6 (r266:84292, Jul 23 2015, 15:22:56)
我的问题是:
- 为什么不使用我在wsgi config中给出的python?
- 如果使用的是/usr/bin/python,那为什么显示为2.7?
- 如何让我的服务器运行 python 2.7?
【问题讨论】:
-
你是如何安装 mod_wsgi 的?如果您从 centos 存储库安装它,它可能是针对 python2.6 编译的,并且与 python2.7 不兼容。您还需要自己编译 mod_wsgi。
标签: python django apache python-2.7 mod-wsgi