views:

104

answers:

1

I recently updated from Python 2.5 to 2.7 (I tried 2.6 during my hassles) and while everything works fine from the command line or in the Django runserver, mod_wsgi cannot load any module that contains DLLs (pyd) built with MSVC.

For example, if I build my own versions of pycrypto or lxml then I will get the following error only from mod_wsgi:

ImportError at /
DLL load failed: The specified module could not be found.

Even the official PIL binaries will fail to import the _imaging C module in mod_wsgi but that may be another problem.

However, if I use a version of pycrypto built with MinGW from somewhere like http://www.voidspace.org.uk/python/modules.shtml#pycrypto then it will import fine even in mod_wsgi. I don't find this solution satisfactory though since the whole reason I updated Python was to avoid needing to hunt for prebuilt binaries and I can't build them myself because MinGW fails >50% of the time for me.

EDIT2: I noticed this in Python27/Lib/distutils/msvc9compiler.py on lines 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

This probably explains why everything works from the command line but not in mod_wsgi. Commenting all this out seems to fix the problem but doesn't feel like the proper fix. The question now is where to put msvcr90.dll so that Apache can use it? I notice that Apache's bin folder contains msvcr70.dll and msvcr80.dll but putting 90 in there doesn't work.

+1  A: 
atzz
They're missing MSVCR90.DLL (and GPSVC and IESHIMS). I put MSVCR90.DLL alongside AES.pyd and Dependency Walker passes but Apache gives a runtime error. I do have the VC redist and MSVCR90.dll is in various folders under C:\Windows\winsxs. Any ideas?
Kyle MacFarlane
I edited the original question to show how AES.pyd is actually built. It would have gotten mangled as a comment.
Kyle MacFarlane
@Kyle MacFarlane - I've edited my answer in response to the comments
atzz
@atzz - I've edited the question again. Any ideas on how it currently stands?
Kyle MacFarlane