Django WSGI Script Won't load due to a Python

2019-07-20 01:06发布

问题:

I'm trying to get Django to run through mod_wsgi on Apache2.22 but I'm getting an internal 500 error. I know there are other questions for this, but they don't have my specific error. Here is my traceback:

[Sat Jun 16 02:17:48 2012] [info] [client 128.227.11.143] mod_wsgi (pid=23071, process='partender', application='www.***.com|'): Loading WSGI script '/usr/home/***.com/zpencerq/part/apache/django.wsgi'.
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143] mod_wsgi (pid=23071): Target WSGI script '/usr/home/***.com/zpencerq/part/apache/django.wsgi' cannot be loaded as Python module.
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143] mod_wsgi (pid=23071): Exception occurred processing WSGI script '/usr/home/***.com/zpencerq/part/apache/django.wsgi'.
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143] Traceback (most recent call last):
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143]   File "/usr/home/partender.myprotosite.com/zpencerq/part/apache/django.wsgi", line 9, in <module>
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143]     import django.core.handlers.wsgi
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143]   File "/usr/local/lib/python2.7/site-packages/django/core/handlers/wsgi.py", line 2, in <module>
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143]     from threading import Lock
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143]   File "/usr/local/lib/python2.7/threading.py", line 15, in <module>
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143]     from collections import deque
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143]   File "/usr/local/lib/python2.7/collections.py", line 9, in <module>
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143]     from operator import itemgetter as _itemgetter
[Sat Jun 16 02:17:48 2012] [error] [client 128.227.11.143] ImportError: /usr/local/lib/python2.7/lib-dynload/operator.so: Undefined symbol "_PyUnicodeUCS4_AsDefaultEncodedString"

it seems to be an issue with python but I have no idea what to do with that last error in the traceback. is that a problem with the python install? I have done the simple WSGI hello world app, and that works perfectly fine. It's an issue with makign the django call.

I used 'ldd' on mod_wsgi.so and got the following output:

root@blah# ldd mod_wsgi.so
mod_wsgi.so:
ldd: mod_wsgi.so: Shared object "mod_wsgi.so" not found, required by "ldd"
mod_wsgi.so: exit status 1

回答1:

Most likely your mod_wsgi is compiled against one Python installation but you are trying to force it to use a different Python installation. The reason you are having a problem is because one Python installation was compiled with UCS2 support and the other UCS4.

Use 'ldd' on mod_wsgi.so to show what Python installation it is trying to use and then provide that information as part of question along with mod_wsgi configuration or WSGI script contents where you are trying to force it to use different Python installation, or incompatible virtual environment.