1

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?

Thorsten Kranz
  • 12,492
  • 2
  • 39
  • 56
  • Thanks for your answer. I'll Check it tomorrow morning. – Thorsten Kranz Apr 16 '14 at 17:53
  • I tried your suggestion. Please see my **Update** for the results – Thorsten Kranz Apr 17 '14 at 05:57
  • 2
    It's probably easiest to embed a manifest into `geos_c.dll`, e.g. with `mt.exe -manifest geos_c.dll.MANIFEST -outputresource:geos_c.dll;2` where the manifest is ` ` – cgohlke Apr 17 '14 at 07:29
  • I definitely cannot really participate in this discussion - my knowledge about DLLs is too limited. Do you know about the "version A/B" story? – Thorsten Kranz Apr 17 '14 at 11:10
  • @cgohlke: Your solution actually works. It would be great if you could put your text into an answer and maybe explain shortly what it does. Then I'd immediately updvote it. BTW, thanks for your great work for the Python ecosystem. – Thorsten Kranz Apr 17 '14 at 14:12
  • While you wait for Christoph's answer, you may want to read [Troubleshooting C/C++ Isolated Applications and Side-by-side Assemblies](http://msdn.microsoft.com/en-us/library/ms235342%28v=vs.90%29.aspx). – Eryk Sun Apr 18 '14 at 14:59
  • @cgohlke - any response to this? i gmailed you directly -- i'm trying to solve this: https://github.com/Toblerity/Shapely/issues/104#issuecomment-110198935 but i don't understand your comment here – user1441998 Jun 09 '15 at 06:35
  • 1
    That comment is no longer relevant for the latest builds. – cgohlke Jun 09 '15 at 07:15

0 Answers0