apache2 + mod_wsgi下的soaplib(lxml)问题
当我用apache2和mod_wsgi启动我的应用时,出现了以下问题:
Exception Type: ImportError Exception Value: DLL load failed: The specified module could not be found.
在这一行:
from lxml import etree
用Django开发服务器时,一切都运行得很好。我的电脑上安装了Visual C++ 2008运行库。
依赖项检查工具告诉我,msvcrt90.dll这个文件缺失了。不过,cx_Oracle也有同样的问题,但cx_Oracle的dll文件加载得很正常。
有没有什么想法可以解决这个问题?
我在使用的是64位的Windows 2003服务器和32位的Windows XP SP3,Python版本是32位的2.7,cx_Oracle版本是32位的5.0.4。
更新:我下载了libxml2-2.7.7和libxslt-1.1.26。
我尝试用命令setup.py build --compiler mingw32来构建。
Building lxml version 2.3. Building with Cython 0.14.1. ERROR: 'xslt-config' is not recognized as an internal or external command, operable program or batch file. ** make sure the development packages of libxml2 and libxslt are installed ** Using build configuration of libxslt running build running build_py running build_ext skipping 'src/lxml\lxml.etree.c' Cython extension (up-to-date) building 'lxml.etree' extension C:\MinGW\bin\gcc.exe -mno-cygwin -mdll -O -Wall -IC:\Python27\include -IC:\Python27\PC -c src/lxml\lxml.etree.c -o build\temp.win32-2.7\Release\src\lxml\lxml.et ree.o -w writing build\temp.win32-2.7\Release\src\lxml\etree.def C:\MinGW\bin\gcc.exe -mno-cygwin -shared -s build\temp.win32-2.7\Release\src\lxml\lxml.etree.o build\temp.win32-2.7\Release\src\lxml\etree.def -LC:\Python27\lib s -LC:\Python27\PCbuild -llibxslt -llibexslt -llibxml2 -liconv -lzlib -lWS2_32 -lpython27 -lmsvcr90 -o build\lib.win32-2.7\lxml\etree.pyd build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0xd11): undefined reference to `_imp__xmlFree' build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0xd24): undefined reference to `_imp__xmlFree' build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0x1ee92): undefined reference to `_imp__xmlFree' build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0x1eed6): undefined reference to `_imp__xmlFree' build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0x2159e): undefined reference to `_imp__xmlMalloc' build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0x2e741): undefined reference to `_imp__xmlFree' build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0x2e784): undefined reference to `_imp__xmlFree' build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0x3f157): undefined reference to `_imp__xmlFree' build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0x3f19a): undefined reference to `_imp__xmlFree' build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0x3f4ac): undefined reference to `_imp__xmlFree' build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0x3f4ef): more undefined references to `_imp__xmlFree' follow build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0xb1ad5): undefined reference to `xsltLibxsltVersion' build\temp.win32-2.7\Release\src\lxml\lxml.etree.o:lxml.etree.c:(.text+0xb1b9a): undefined reference to `xsltDocDefaultLoader' collect2: ld returned 1 exit status error: command 'gcc' failed with exit status 1
更新2:我明白了为什么导入cx_Oracle可以正常工作:cx_Oracle.pyd文件依赖于"MSVCRT.dll",而etree.pyd文件没有这个依赖。
1 个回答
这确实是因为 'msvcrt90.dll' 这个文件。从 Python 2.6 的某些小更新开始,他们不再自动为扩展模块链接这个 DLL,而是依赖 Python 的可执行文件来处理这个问题。然而,当 Python 嵌入到其他系统中时,就需要这个可执行文件去链接 DLL,而在 Apache 的情况下,它并没有这样做。因此,Python 的这个变化导致了许多在 Windows 上嵌入 Python 的系统出现了问题,唯一的解决办法就是每个扩展模块都要自己处理所需的 DLL 依赖关系,但很多模块并没有这样做。比如说,psycopg2 这个扩展就受到了很大影响,他们现在已经修改了构建方式,自己添加了这个依赖。你可以去查查关于 psycopg2 的问题,解决方案之一是使用 MinGW 编译器在 Windows 上重新构建这些扩展。