Python

在 Apache 中執行 WSGI 應用程序時出現 ImportError:未定義符號:PyUnicodeUCS2_DecodeUTF8

  • June 21, 2016

我正在嘗試在 SLES 11P1 上的 Apache 下執行 MoinMoin。當有人嘗試訪問該站點時,我的 Apache 日誌中出現以下錯誤:

mod_wsgi (pid=20772): Target WSGI script '/srv/www/wiki/moin.wsgi' cannot be loaded as Python module.
mod_wsgi (pid=20772): Exception occurred processing WSGI script '/srv/www/wiki/moin.
wsgi'.
Traceback (most recent call last):
 File "/srv/www/wiki/moin.wsgi", line 44, in <module>
   from MoinMoin.web.serving import make_application
 File "/usr/local/lib64/python2.6/site-packages/MoinMoin/web/serving.py", line 14, in <module>
   from MoinMoin import version, log
 File "/usr/local/lib64/python2.6/site-packages/MoinMoin/log.py", line 92, in <module>
   import logging.config
 File "/usr/lib/python2.6/logging/config.py", line 30, in <module>
   import sys, logging, logging.handlers, string, socket, struct, os, traceback, types
 File "/usr/lib/python2.6/logging/handlers.py", line 27, in <module>
   import logging, socket, types, os, string, cPickle, struct, time, re
ImportError: /usr/lib64/python2.6/lib-dynload/cPickle.so: undefined symbol: PyUnicodeUCS2_DecodeUTF8

但是,如果我從 Python 解釋器手動執行失敗的語句,我沒有問題:

$ python
'import site' failed; use -v for traceback
Python 2.6.6 (r266:84292, Feb 17 2011, 08:36:48) 
[GCC 4.3.4 [gcc-4_3-branch revision 152973]] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import logging, socket, types, os, string, cPickle, struct, time, re
>>>

在 Apache 下執行時會導致該錯誤,但在命令行執行 Python 時不會導致該錯誤?

編輯:看起來他們正在訪問不同的共享庫。Apache 正在命中/usr/lib64/python2.6/lib-dynload/cPickle.so,而我在命令行呼叫的 Python 解釋器正在命中/usr/lib/python2.6/lib-dynload/cPickle.so

$ python -v 
...
>>> import cPickle
dlopen("/usr/lib/python2.6/lib-dynload/cPickle.so", 2);
dlopen("/usr/lib/python2.6/lib-dynload/cStringIO.so", 2);

正如您自己所注意到的,當您從命令行執行不同的 python 二進製文件時,Apache(64 位)正在載入不同的庫。修復 Python2.6 的 64 位安裝的二進製文件/庫。這應該有望消失。

引用自:https://unix.stackexchange.com/questions/7594