我在amd64平台上使用ubuntu 11.04进行了这样的cfg:
alsp我将mod_wsgi.so重新编译为自定义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
#/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 site config:
<VirtualHost 192.168.1.3>
ServerAdmin admin@wsgi.debianworld.ru
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
我的错误日志中出错:
[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没有。 请帮忙)
答案 0 :(得分:2)
在Linux机器上提供的操作系统Python版本是针对UCS4 Unicode字符宽度编译的。如果您使用源代码构建,如果您没有明确说明,则默认为UCS2。结果是你的系统Python 2.5和/ usr / local下的本地版本期望Unicode字符的宽度不同,并且因为当你使用为另一个Python编译的对象时,Unicode函数将UCS类型作为名称的一部分,你得到Unicode函数的未定义错误。
为什么会出现这种情况,正如其他答案暗示的那样,mod_wsgi.so实际上是在/ usr / local / lib下获取系统范围的UCS4 libpython2.5.so文件而不是UCS2 Python的文件。虽然您可以设置LD_LIBRARY_PATH以使进程首先查看/ usr / local / lib,但在Apache下这是一件痛苦的事情。相反,你应该做的是再次从源代码重建mod_wsgi并执行:
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中选择正确的库。
答案 1 :(得分:1)
它正在加载系统Python。您需要使用$LD_LIBRARY_PATH
将其指向VE Python。有关详细信息,请参阅ld.so(8)
手册页。