Discussion:
[Community] trouble with Shapely in Apache under WSGI
Harasty, Daniel J
2013-07-16 15:03:24 UTC
Permalink
I realize that - strictly speaking - this is probably not a bug in Shapely, but I would appreciate any advice.

I'd like to use Shapely in this environment:


* In a Python script implementing a WSGI application

* Deployed on Windows behind Apache httpd 2.x

Alas, I get this error logged by Apache:


* WindowsError: [Error 126] The specified module could not be found

The traceback reveals a problem loading the "geos_c.dll":


File "C:\\Python\\Python26\\lib\\site-packages\\shapely\\geos.py", line 76, in <module>
_lgeos = CDLL("geos_c.dll") # DJH
File "C:\\Python\\Python26\\lib\\ctypes\\__init__.py", line 354, in __init__
self._handle = _dlopen(self._name, mode)

This is thrown immediately upon "import shapely.wkb", or any other Shapely library that imports shapely.geos.

This has the smell of some sort of "path problem", but I have fiddled with every possible PATH and PYTHONPATH setting both inside and outside of Apache.

I can repeat this in a diminutive app (not only my larger application), which shows that even loading nothing else, I can trip this error. I'd be willing to post/share my sample code and fragment from my Apache conf... but you'd have to already have some familiarity with Apache and Python WSGI on Windows for it to mean much.

Note that calling similar script (using Shapely) as a CGI (behind Apache) work fine. So this sounds like a DLL loading problem peculiar to Windows+Apache+mod_wsgi. (Not a Shapely or geos_c.dll bug, per se.) However, none of my other Python+WSGI+Window+Apache scripts are having the same problem.

Any advice?

Thanks,

Dan Harasty
dharasty at appcomsci.com<mailto:dharasty at appcomsci.com>


-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20130716/a145ecdf/attachment.htm>
Howard Butler
2013-07-16 15:13:05 UTC
Permalink
Post by Harasty, Daniel J
Note that calling similar script (using Shapely) as a CGI (behind Apache) work fine. So this sounds like a DLL loading problem peculiar to Windows+Apache+mod_wsgi. (Not a Shapely or geos_c.dll bug, per se.) However, none of my other Python+WSGI+Window+Apache scripts are having the same problem.
Any advice?
Just a WAG, but doesn't Apache require that you somehow bless a DLL if you're loading it at runtime inside the Apache process (which WSGI is going to want to do, whereas CGI is spawning a separate process)?

Another debugging trick is to start apache from a cmd.exe so that its dlopen calls are not suppressed. Maybe you have 64 vs 32 bit issues, or one of geos_c.dll's dependent DLLs isn't in the path.

Hope this helps,

Howard
Oleksandr Huziy
2013-07-16 15:24:00 UTC
Permalink
Harasty:

On Linux or Mac you would have to specify $LD_LIBRARY_PATH to include the
path to the folder with your native library if it is installed in an
unusual place. I have no idea if it'll work for windows. One way to check
if your fiddling with the env variables actually has an effect, you could
output the values inside of your python script like so:
import os
print os.environ #this is a dictionary of env variables

HTH

Cheers

--
Oleksandr (Sasha) Huziy




2013/7/16 Harasty, Daniel J <dharasty at appcomsci.com>
I realize that ? strictly speaking ? this is probably not a bug in
Shapely, but I would appreciate any advice.****
** **
I?d like to use Shapely in this environment:****
** **
**? **In a Python script implementing a WSGI application****
**? **Deployed on Windows behind Apache httpd 2.x****
** **
Alas, I get this error logged by Apache:****
** **
**? **WindowsError: [Error 126] The specified module could not be
found****
** **
The traceback reveals a problem loading the ?geos_c.dll?:****
** **
File "C:\\Python\\Python26\\lib\\site-packages\\shapely\\geos.py", line
76, in <module>****
_lgeos = CDLL("geos_c.dll") # DJH****
File "C:\\Python\\Python26\\lib\\ctypes\\__init__.py", line 354, in
__init__****
self._handle = _dlopen(self._name, mode)****
** **
This is thrown immediately upon ?import shapely.wkb?, or any other Shapely
library that imports shapely.geos.****
** **
This has the smell of some sort of ?path problem?, but I have fiddled with
every possible PATH and PYTHONPATH setting both inside and outside of
Apache.****
** **
I can repeat this in a diminutive app (not only my larger application),
which shows that even loading nothing else, I can trip this error. I?d be
willing to post/share my sample code and fragment from my Apache conf? but
you?d have to already have some familiarity with Apache and Python WSGI on
Windows for it to mean much.****
** **
Note that calling similar script (using Shapely) as a CGI (behind Apache)
work fine. So this sounds like a DLL loading problem peculiar to
Windows+Apache+mod_wsgi. (Not a Shapely or geos_c.dll bug, per se.)
However, none of my other Python+WSGI+Window+Apache scripts are having the
same problem.****
** **
Any advice?****
** **
Thanks,****
** **
Dan Harasty****
dharasty at appcomsci.com****
** **
** **
_______________________________________________
Community mailing list
Community at lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20130716/0367f5eb/attachment.htm>
Jeff Heard
2013-07-16 15:34:54 UTC
Permalink
You should look up whatever equivalent of LD_LIBRARY_PATH that exists in
Windows. I've forgotten where it is but that's your problem. The geos dll
needs to be in the library path of the wsgi executable
On Jul 16, 2013 11:03 AM, "Harasty, Daniel J" <dharasty at appcomsci.com>
I realize that ? strictly speaking ? this is probably not a bug in
Shapely, but I would appreciate any advice.****
** **
I?d like to use Shapely in this environment:****
** **
**? **In a Python script implementing a WSGI application****
**? **Deployed on Windows behind Apache httpd 2.x****
** **
Alas, I get this error logged by Apache:****
** **
**? **WindowsError: [Error 126] The specified module could not be
found****
** **
The traceback reveals a problem loading the ?geos_c.dll?:****
** **
File "C:\\Python\\Python26\\lib\\site-packages\\shapely\\geos.py", line
76, in <module>****
_lgeos = CDLL("geos_c.dll") # DJH****
File "C:\\Python\\Python26\\lib\\ctypes\\__init__.py", line 354, in
__init__****
self._handle = _dlopen(self._name, mode)****
** **
This is thrown immediately upon ?import shapely.wkb?, or any other Shapely
library that imports shapely.geos.****
** **
This has the smell of some sort of ?path problem?, but I have fiddled with
every possible PATH and PYTHONPATH setting both inside and outside of
Apache.****
** **
I can repeat this in a diminutive app (not only my larger application),
which shows that even loading nothing else, I can trip this error. I?d be
willing to post/share my sample code and fragment from my Apache conf? but
you?d have to already have some familiarity with Apache and Python WSGI on
Windows for it to mean much.****
** **
Note that calling similar script (using Shapely) as a CGI (behind Apache)
work fine. So this sounds like a DLL loading problem peculiar to
Windows+Apache+mod_wsgi. (Not a Shapely or geos_c.dll bug, per se.)
However, none of my other Python+WSGI+Window+Apache scripts are having the
same problem.****
** **
Any advice?****
** **
Thanks,****
** **
Dan Harasty****
dharasty at appcomsci.com****
** **
** **
_______________________________________________
Community mailing list
Community at lists.gispython.org
http://lists.gispython.org/mailman/listinfo/community
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://lists.gispython.org/pipermail/community/attachments/20130716/433e4029/attachment-0001.htm>
Loading...