【发布时间】:2011-04-12 00:01:42
【问题描述】:
我最近从 Python 2.5 更新到 2.7(我在遇到麻烦时尝试了 2.6),虽然在命令行或 Django 运行服务器中一切正常,但 mod_wsgi 无法加载任何包含使用 MSVC 构建的 DLL (pyd) 的模块。
例如,如果我构建自己的 pycrypto 或 lxml 版本,那么我只会从 mod_wsgi 收到以下错误:
ImportError at /
DLL load failed: The specified module could not be found.
即使是官方的 PIL 二进制文件也无法在 mod_wsgi 中导入 _imaging C 模块,但这可能是另一个问题。
但是,如果我使用像 http://www.voidspace.org.uk/python/modules.shtml#pycrypto 这样的地方使用 MinGW 构建的 pycrypto 版本,那么即使在 mod_wsgi 中它也可以正常导入。我觉得这个解决方案并不令人满意,因为我更新 Python 的全部原因是为了避免需要寻找预构建的二进制文件,而且我无法自己构建它们,因为 MinGW 对我来说超过 50% 的时间都失败了。
编辑2: 我在 Python27/Lib/distutils/msvc9compiler.py 第 680-705 行注意到了这一点:
try:
# Remove references to the Visual C runtime, so they will
# fall through to the Visual C dependency of Python.exe.
# This way, when installed for a restricted user (e.g.
# runtimes are not in WinSxS folder, but in Python's own
# folder), the runtimes do not need to be in every folder
# with .pyd's.
manifest_f = open(manifest_file)
try:
manifest_buf = manifest_f.read()
finally:
manifest_f.close()
pattern = re.compile(
r"""<assemblyIdentity.*?name=("|')Microsoft\."""\
r"""VC\d{2}\.CRT("|').*?(/>|</assemblyIdentity>)""",
re.DOTALL)
manifest_buf = re.sub(pattern, "", manifest_buf)
pattern = "<dependentAssembly>\s*</dependentAssembly>"
manifest_buf = re.sub(pattern, "", manifest_buf)
manifest_f = open(manifest_file, 'w')
try:
manifest_f.write(manifest_buf)
finally:
manifest_f.close()
except IOError:
pass
这可能解释了为什么一切都可以在命令行中运行,而不是在 mod_wsgi 中。评论所有这些似乎可以解决问题,但感觉不是正确的解决方法。现在的问题是把 msvcr90.dll 放在哪里以便 Apache 可以使用它?我注意到 Apache 的 bin 文件夹包含 msvcr70.dll 和 msvcr80.dll,但将 90 放在那里不起作用。
【问题讨论】:
-
在 IIS 下使用 pyodbc 跳过删除清单也对我有用
标签: python visual-c++ mod-wsgi