GeoDjango - GDAL library giving error

2020-07-02 12:03发布

问题:

I am trying to get GeoDjango running on ubuntu and have hit a problem with GDAL.

I have downloaded and installed GDAL without problem.

I had to add the following line to my project settings:

GDAL_LIBRARY_PATH = '/usr/local/lib/libgdal.so.1.15.1'  

When I check in the shell all is good:

In [1]: from django.contrib.gis import gdal
In [2]: gdal.HAS_GDAL
Out[2]: True

However when I try and run ogrinfo as in the official tutorial I get the following error:

$ ogrinfo world/data/TM_WORLD_BORDERS-0.3.shp
ogrinfo: error while loading shared libraries: libgdal.so.1: cannot open shared object file: No such file or directory

GDAL files are located at:

/usr/local/lib/libgdal.a
/usr/local/lib/libgdal.la
/usr/local/lib/libgdal.so
/usr/local/lib/libgdal.so.1
/usr/local/lib/libgdal.so.1.15.1

libgdal.so and libgdal.so.1 both symlink to libgdal.so.15.1

Any help would be much appreciated.

回答1:

So, for the record, the answer was to add the library path /usr/local/lib/ to /etc/ld.so.conf, then run $ sudo ldconfig



回答2:

sudo ldconfig

Often is all you need. Just check /etc/ld.so.conf before you start adding paths, /usr/local/lib may already be listed.



回答3:

According to django documentation 'The most common problem when installing GeoDjango is that the external shared libraries (e.g., for GEOS and GDAL) cannot be located.'

The usual path for gdal library installed via source is /usr/local/lib, Therefore if you run the bash command:

export LD_LIBRARY_PATH=/usr/local/lib

python should then be able to find



回答4:

$ sudo echo /usr/local/lib >> /etc/ld.so.conf
$ sudo ldconfig

https://docs.djangoproject.com/en/dev/ref/contrib/gis/install/#setting-system-library-path