Cartopy in IIS isapi-wsgi application fails to imp

2019-08-12 18:17发布

问题:

I'm trying to use cartopy in a isapi-wsgi application under IIS 7.

I have many applications working with isapi-wsgi, so I'm 100% sure the way I set up my isapi-wsgi is correct.

I also have cartopy working correctly in a normal Python-console, so this also is no problem.

When the code comes to

import cartopy.io.shapereader

it fails.

The relevant part of the traceback is

Traceback (most recent call last):
  ...
  File "C:\Python27\lib\site-packages\cartopy\__init__.py", line 23, in <module>
    import shapely.speedups
  File "C:\Python27\lib\site-packages\shapely\speedups\__init__.py", line 3, in <module>
    from shapely.geometry import linestring, polygon
  File "C:\Python27\lib\site-packages\shapely\geometry\__init__.py", line 4, in <module>
    from .base import CAP_STYLE, JOIN_STYLE
  File "C:\Python27\lib\site-packages\shapely\geometry\base.py", line 9, in <module>
    from shapely.coords import CoordinateSequence
  File "C:\Python27\lib\site-packages\shapely\coords.py", line 8, in <module>
    from shapely.geos import lgeos
  File "C:\Python27\lib\site-packages\shapely\geos.py", line 81, in <module>
    _lgeos = CDLL("geos_c.dll")
  File "C:\Python27\Lib\ctypes\__init__.py", line 365, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

As mentioned earlier, this import only fails under IIS and isapi_wsgi.

My configuration:

  • Windows Server 2008 R2

  • IIS 7.5

  • Python(x,y) 2.7.6.0 with all Python-libraries installed (32 bit)

  • From http://www.lfd.uci.edu/~gohlke/pythonlibs/:

    • Cartopy 0.10
    • Shapely 1.3
    • pyshp 1.2
    • all with correct bitness and Python version

My application pool in IIS is configured to allow 32bit applications.

I also investigated the dependencies of geos_c.dll using "Dependency Walker". It shows that it depends on the well-known "msvcr90.dll" and "msvcp90.dll" files. I suspected that the DLL load failed because these dependencies couldn't be resolved, but I actually do have the "MS Visual ... Redistributable" installed. Even copying those DLLs to various folders, like shapely's, the virtual directory, different directories in the PATH etc didn't solve my problem.

I'm really stuck here and do not know any further. Does anybody have some advice?

Update

As suggested by @eryksun I tried to load the msvc[r|p]90.dll files within IIS. I used the following code snippet:

sio = StringIO()
for dll_name in ["msvcp90.dll", "msvcr90.dll"]:
    try:
        print >> sio, "Loading {} ...".format(dll_name),
        handle = ctypes.CDLL(dll_name)
        print >> sio, "successful, {}".format(str(handle))
    except Exception, e:            
        print >> sio, "failed, {}, {}".format(str(type(e)), str(e))

And this then gives me

Loading msvcp90.dll ... failed, <type 'exceptions.WindowsError'>, [Error 126] The specified module could not be found
Loading msvcr90.dll ... failed, <type 'exceptions.WindowsError'>, [Error 126] The specified module could not be found

So this should indeed be the root of all evil in this case. Within a normal interpreter, both calls succeed.

Update 2

Interestingly, when I search matching (32bit) msvc[p|r]90.dll files on my machine and copy them to the working directory of my isapi-wsgi process, I get a completely different error:

 Loading msvcp90.dll ... failed, <type 'exceptions.WindowsError'>, [Error 1114] A dynamic link library (DLL) initialization routine failed
 Loading msvcr90.dll ... failed, <type 'exceptions.WindowsError'>, [Error 1114] A dynamic link library (DLL) initialization routine failed

and even a pop-up appears. This seems to be related to this issue. Any ideas? Where can I find this "version B" DLL?