问题描述
我在使用ubuntu 11.04的amd64平台上有这样的cfg:
I have such cfg on my amd64 platform with ubuntu 11.04:
- 从源代码构建python2.5到/usr/local/python2.5 在/home/se7en/.virtualenvs/e-py25上的
- virtualenv
- build python2.5 from source to /usr/local/python2.5
- virtualenv at /home/se7en/.virtualenvs/e-py25
alsp我将mod_wsgi.so重新编译为自定义python:
alsp i recompile mod_wsgi.so to custom python:
se7en@se7en-System-Product-Name:~$ ldd /usr/lib/apache2/modules/mod_wsgi.so
linux-vdso.so.1 => (0x00007fff5af6c000)
libpython2.5.so.1.0 => /usr/lib/libpython2.5.so.1.0 (0x00007f7bed14b000)
libpthread.so.0 => /lib/x86_64-linux-gnu/libpthread.so.0 (0x00007f7becf2d000)
libdl.so.2 => /lib/x86_64-linux-gnu/libdl.so.2 (0x00007f7becd28000)
libutil.so.1 => /lib/x86_64-linux-gnu/libutil.so.1 (0x00007f7becb25000)
libm.so.6 => /lib/x86_64-linux-gnu/libm.so.6 (0x00007f7bec8a0000)
libc.so.6 => /lib/x86_64-linux-gnu/libc.so.6 (0x00007f7bec50b000)
/lib64/ld-linux-x86-64.so.2 (0x00007f7bed717000)
django.wsgi
django.wsgi
#/usr/local/python2.5/bin/python
# -*- coding: utf-8 -*-
import os, sys
sys.stdout = sys.stderr
dn = os.path.dirname
PROJECT_ROOT = os.path.abspath( (dn(__file__)) )
#DJANGO_PROJECT_ROOT = os.path.join(PROJECT_ROOT, 'apps')
DJANGO_PROJECT_ROOT = PROJECT_ROOT
sys.path.insert(0, '/usr/local/python2.5/lib/python2.5/site-packages' )
sys.path.insert(0,'/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages')
sys.path.insert(0, DJANGO_PROJECT_ROOT )
os.environ['DJANGO_SETTINGS_MODULE'] = 'settings'
print sys.version #return 2.5.5 (r255:77872, Apr 15 2011, 22:12:51
print sys.path
import django.core.handlers.wsgi
application = django.core.handlers.wsgi.WSGIHandler()
apache网站配置:
apache site config:
<VirtualHost 192.168.1.3>
ServerAdmin [email protected]
ServerName wsgi.debianworld.ru
ErrorLog /home/se7en/workspace/lxchg/logs/error_log
CustomLog /home/se7en/workspace/lxchg/logs/access_log common
WSGIScriptAlias / /home/se7en/workspace/lxchg/django.wsgi
Alias "/media/" "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/contrib/admin/media/"
<Location "/media/">
SetHandler None
</Location>
Alias "/main_media/" "/home/se7en/workspace/lxchg/main_media/"
<Location "/main_media/">
SetHandler None
</Location>
</VirtualHost>
WSGIPythonHome /home/se7en/.virtualenvs/e-py25
#WSGIPythonExecutable /usr/local/python2.5/bin/python
我的错误日志中出现错误:
I got an error in my error log:
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] mod_wsgi (pid=2955): Exception occurred processing WSGI script '/home/se7en/workspace/lxchg/django.wsgi'.
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] Traceback (most recent call last):
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/core/handlers/wsgi.py", line 248, in __call__
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] response = self.get_response(request)
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/core/handlers/base.py", line 141, in get_response
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] return self.handle_uncaught_exception(request, resolver, sys.exc_info())
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/core/handlers/base.py", line 176, in handle_uncaught_exception
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] if resolver.urlconf_module is None:
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/core/urlresolvers.py", line 239, in _get_urlconf_module
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] self._urlconf_module = import_module(self.urlconf_name)
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/utils/importlib.py", line 35, in import_module
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] __import__(name)
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "C:\\workspace\\sdl\\lxchg\\urls.py", line 3, in <module>
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/views/generic/create_update.py", line 1, in <module>
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] from django.forms.models import ModelFormMetaclass, ModelForm
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/forms/__init__.py", line 17, in <module>
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] from models import *
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/forms/models.py", line 6, in <module>
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] from django.db import connections
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/db/__init__.py", line 77, in <module>
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] connection = connections[DEFAULT_DB_ALIAS]
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/db/utils.py", line 92, in __getitem__
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] backend = load_backend(db['ENGINE'])
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] File "/home/se7en/.virtualenvs/e-py25/lib/python2.5/site-packages/django/db/utils.py", line 50, in load_backend
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] raise ImproperlyConfigured(error_msg)
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] ImproperlyConfigured: 'django.db.backends.mysql' isn't an available database backend.
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] Try using django.db.backends.XXX, where XXX is one of:
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] 'dummy', 'mysql', 'oracle', 'postgresql', 'postgresql_psycopg2', 'sqlite3'
[Wed Jun 22 13:45:54 2011] [error] [client 192.168.1.3] Error was: /home/se7en/.virtualenvs/e-py25/lib/python2.5/lib-dynload/array.so: undefined symbol: PyUnicodeUCS2_FromUnicode
然后我通过manage.py runserver启动项目,但它不能通过mod_wsgi启动.请帮忙)
Then i start project via manage.py runserver it works, but via mod_wsgi do not.please help)
推荐答案
Linux盒子上操作系统提供的Python版本是针对UCS4 Unicode字符宽度进行编译的.如果您是从源代码构建的,则除非您未明确说明,否则它将默认为UCS2.结果是您的系统Python 2.5和/usr/local下的本地版本期望Unicode字符具有不同的宽度,并且由于Unicode函数将UCS类型作为名称的一部分,因此,当您使用为一个Python编译的对象与另一个Python一起编译时,您会收到Unicode函数的未定义错误.
The operating system supplied Python versions on Linux boxes are compiled for UCS4 Unicode character width. If you build from source code, if you don't explicitly say otherwise it will default to UCS2. The result is that your system Python 2.5 and local version under /usr/local are expecting different widths for Unicode characters and since Unicode functions have the UCS type as part of the name, when you are using objects compiled for one Python with the other, you get undefined errors for the Unicode functions.
为什么出现这种情况,正如其他答案所暗示的那样,mod_wsgi.so实际上是在系统范围内的UCS4 libpython2.5.so文件中,而不是在/usr/local/lib下的UCS2 Python文件中.尽管您可以设置LD_LIBRARY_PATH来使进程首先在/usr/local/lib中查找,但这在Apache下是很痛苦的.相反,您应该做的是再次从源代码重新构建mod_wsgi并执行以下操作:
Why this is occuring as hinted at by other answer is that mod_wsgi.so is actually picking up the system wide UCS4 libpython2.5.so file instead of that for UCS2 Python under /usr/local/lib. Although you could set LD_LIBRARY_PATH to make a process to look in /usr/local/lib first, that is a pain to do under Apache. Instead what you should do is rebuild mod_wsgi from source code again and do:
make distclean
./configure --with-python=/usr/local/bin/python2.5
LD_RUN_PATH=/usr/local/lib make
sudo make install
通过在调用"make"时在命令上将LD_RUN_PATH设置为环境变量,链接器会将/usr/local/lib嵌入到直接到mod_wsgi.so的库搜索路径中.这样,它将在运行时找到正确的libpython2.5.so,而无需设置LD_LIBRARY_PATH.您可以通过在生成的mod_wsgi.so上运行"ldd"来确认它是否工作,然后从/usr/local/lib中选择正确的库.
By setting LD_RUN_PATH as environment variable on the command when invoking 'make', the linker will embed /usr/local/lib into library search path direct into mod_wsgi.so. That way it will find correct libpython2.5.so at run time without needing to set LD_LIBRARY_PATH. You can confirm it worked by running 'ldd' on the resultant mod_wsgi.so and it should then pick up correct library from /usr/local/lib.
这篇关于mod_wsgi python2.5 ubuntu 11.04问题的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!