开发者

libgeos_c-1.dll can't be loaded by Python

I'm building my first GeoDjango project but I'm kinda desperate.

I'v installed PostgreSQL 9 and PostGis 1.5 through one-click installer on Windows. So everthing is there. I set GEOS_LIBRARY_PATH to the full path of libgeos_c-1.dll in settings.py. But when I run manage.py syncdb, I encounter the following errors:

  File "C:\Python25\lib\site-packages\django\contrib\gis\geometry\backend\g开发者_开发百科eos.py", line 1, in <module>
    from django.contrib.gis.geos import \
  File "C:\Python25\Lib\site-packages\django\contrib\gis\geos\__init__.py", line 6, in <module>
    from django.contrib.gis.geos.geometry import GEOSGeometry, wkt_regex, hex_regex
  File "C:\Python25\Lib\site-packages\django\contrib\gis\geos\geometry.py", line 14, in <module>
    from django.contrib.gis.geos.coordseq import GEOSCoordSeq
  File "C:\Python25\Lib\site-packages\django\contrib\gis\geos\coordseq.py", line 9, in <module>
    from django.contrib.gis.geos.libgeos import CS_PTR
  File "C:\Python25\lib\site-packages\django\contrib\gis\geos\libgeos.py", line 51, in <module>
    lgeos = CDLL(lib_path)
  File "C:\Python25\lib\ctypes\__init__.py", line 348, in __init__
    self._handle = _dlopen(self._name, mode)
WindowsError: [Error 126] The specified module could not be found

So I open libgeos.py and check the line specified. It's just a simple "CDLL(lib_path)". Apparently lib_path is GEOS_LIBRARY_PATH.

So I create a simple test:

from ctypes import CDLL

lgeos = CDLL('libgeo's path')

Still have the same problem. So it's simply not able to use CDLL to load this dll at all with python. At this stage, I don't know what to do. Please help.


Aparently after set GEOS_LIBRARY_PATH variable using doble '\' slashes works for me, but now launches this error 'module' object has no attribute 'OSMGeoAdmin'


I just run into the same problem after installing Postgresql 9.1 and postgis 2.0 via Windows installers. No need to download anything else. All you have to do is adding this directory into the Windows path: C:\PostgreSQL\9.1\bin or wherever the libgeos_c-1.dll file lives. You may need to reboot if you want the new environment variables to take effect for your IDE. For command lines, just open a new command prompt.

Doing this this way makes setting GEOS_LIBRARY_PATH optional since the required files are already in Windows path.

This may not have worked for the OP back in 2010 but for others who run into the same problem in 2012 going forward, it's probably the simplest solution.


Different things come to my mind, the most obvious being: You did paste the path to the DLL file in there, not just the folder it resides in? No offense meant, just to be on the safe side.

Then, you might also get this error if there are unresolved dependencies, i.e. the DLL's LoadLibrary fails because it is missing another library it depends on. You can easily find that out using Dependency Walker. Load libgeos with depends and look for missing modules, error messages etc. - you might be missing libgeos-X-Y-Z.dll, for example.


Same issue here. Could you maybe be so kind as to share the correct DLL? If that indeed solves the problem. Or is installing OSGeo4W the only way?If so what installation procedure did you follow?


I had the same issue and solved it by:

  1. Reinstalling http://trac.osgeo.org/osgeo4w/ (my installation folder is C:\OSGeo4W64\)
  2. adding the line:

    GEOS_LIBRARY_PATH = 'C:\OSGeo4W64\bin\geos_c.dll'

to settings.py

(following this answer: https://stackoverflow.com/a/21495785/2314737)

This is also mentioned in the official documentation:

When GeoDjango can’t find GEOS, this error is raised:

ImportError: Could not find the GEOS library (tried "geos_c"). Try setting GEOS_LIBRARY_PATH in your settings. The most common solution is to properly configure your Library environment settings or set GEOS_LIBRARY_PATH in your settings.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜