I recently upgraded from Python 2.5 to 2.7 (I tried 2.6 during my problems), and although everything works fine from the command line or on the Django server, mod_wsgi cannot load any module containing a DLL (pyd) built with using MSVC.
For example, if I create 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 not be able to import the _imaging C module into mod_wsgi, but this may be another problem.
However, if I use the version of pycrypto built with MinGW, from somewhere like http://www.voidspace.org.uk/python/modules.shtml#pycrypto , it will even import into mod_wsgi. I did not find this solution satisfactory, although since the whole reason I updated Python was to avoid having to look for ready-made binaries, and I cannot create them myself, because MinGW is not working> 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 (eg # runtimes are not in WinSxS folder, but in Python 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 of this seems to fix the problem, but doesn't seem like the correct fix. Now the question is, where to put msvcr90.dll so that Apache can use it? I noticed that the Apache bin folder contains the msvcr70.dll and msvcr80.dll files, but the attachment 90 in it does not work.
python visual-c ++ mod-wsgi
Kyle MacFarlane
source share