--- django/contrib/gis/geos/libgeos.py 2017-12-02 12:36:16.000000000 -0200 +++ django/contrib/gis/geos/libgeos.py 2017-12-06 08:12:35.806014360 -0200 @@ -8,8 +8,8 @@ """ import logging import os +import sys from ctypes import CDLL, CFUNCTYPE, POINTER, Structure, c_char_p -from ctypes.util import find_library from django.core.exceptions import ImproperlyConfigured from django.utils.functional import SimpleLazyObject, cached_property @@ -19,47 +19,27 @@ def load_geos(): - # Custom library path set? - try: - from django.conf import settings - lib_path = settings.GEOS_LIBRARY_PATH - except (AttributeError, EnvironmentError, - ImportError, ImproperlyConfigured): - lib_path = None - - # Setting the appropriate names for the GEOS-C library. - if lib_path: - lib_names = None - elif os.name == 'nt': - # Windows NT libraries - lib_names = ['geos_c', 'libgeos_c-1'] - elif os.name == 'posix': - # *NIX libraries - lib_names = ['geos_c', 'GEOS'] - else: - raise ImportError('Unsupported OS "%s"' % os.name) - - # Using the ctypes `find_library` utility to find the path to the GEOS - # shared library. This is better than manually specifying each library name - # and extension (e.g., libgeos_c.[so|so.1|dylib].). - if lib_names: - for lib_name in lib_names: - lib_path = find_library(lib_name) - if lib_path is not None: - break - - # No GEOS library could be found. - if lib_path is None: - raise ImportError( - 'Could not find the GEOS library (tried "%s"). ' - 'Try setting GEOS_LIBRARY_PATH in your settings.' % - '", "'.join(lib_names) - ) # Getting the GEOS C library. The C interface (CDLL) is used for # both *NIX and Windows. # See the GEOS C API source code for more details on the library function calls: # http://geos.refractions.net/ro/doxygen_docs/html/geos__c_8h-source.html - _lgeos = CDLL(lib_path) + if os.name == 'posix': + platform = os.uname()[0] + if platform == 'Linux': + libname = 'libgeos_c.so' + elif platform == 'Darwin': + libname = 'libgeos_c.dylib' + _lgeos = CDLL(os.path.join(sys.prefix, 'lib', libname)) + elif os.name == 'nt': + # On Windows, the GDAL binaries have some OSR routines exported with + # STDCALL, while others are not. Thus, the library will also need to + # be loaded up as WinDLL for said OSR functions that require the + # different calling convention. + libname = os.path.join(sys.prefix, 'Library', 'bin', 'geos_c.dll') + _lgeos = CDLL(libname) + else: + raise Exception('No valid platform name. Found {}'.format(os.name)) + # Here we set up the prototypes for the initGEOS_r and finishGEOS_r # routines. These functions aren't actually called until they are # attached to a GEOS context handle -- this actually occurs in