Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Could not find the GDAL library #299

Open
jlesech opened this issue Aug 12, 2020 · 5 comments
Open

Could not find the GDAL library #299

jlesech opened this issue Aug 12, 2020 · 5 comments

Comments

@jlesech
Copy link
Contributor

jlesech commented Aug 12, 2020

I'm facing an issue with django-leaflet v0.27.x related to a missing GDAL library. My Django project was working fine without GDAL until django-leaflet v0.26.0.

I took a look at the recent commits between v0.26.0 and v0.27.0 and I found this one: Drop outdated backport files.

I'm using Python 3.8 on Ubuntu 20.04 and these packages:

Django==2.2.14
django-geojson==3.0.0
django-leaflet==0.27.1
geopy==2.0.0
jsonfield==3.1.0

Stacktrace:

Traceback (most recent call last):
  File "./manage.py", line 21, in <module>
    main()
  File "./manage.py", line 17, in main
    execute_from_command_line(sys.argv)
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/core/management/__init__.py", line 357, in execute
    django.setup()
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
    app_config.import_models()
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/apps/config.py", line 211, in import_models
    self.models_module = import_module(models_module_name)
  File "/usr/lib/python3.8/importlib/__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
  File "<frozen importlib._bootstrap>", line 991, in _find_and_load
  File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 783, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "/home/user/workspace-py/webmapping/myapp/models.py", line 3, in <module>
    from djgeojson.fields import PolygonField
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/djgeojson/fields.py", line 8, in <module>
    from leaflet.forms.widgets import LeafletWidget
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/leaflet/forms/widgets.py", line 2, in <module>
    from django.contrib.gis.forms.widgets import BaseGeometryWidget
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
    from .fields import (  # NOQA
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
    from django.contrib.gis.gdal import GDALException
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
    from django.contrib.gis.gdal.datasource import DataSource
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/contrib/gis/gdal/datasource.py", line 39, in <module>
    from django.contrib.gis.gdal.driver import Driver
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
    from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
    from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
  File "/home/user/venvs/myproject/lib/python3.8/site-packages/django/contrib/gis/gdal/libgdal.py", line 40, in <module>
    raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0", "gdal1.11.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

Is the GDAL library now required?

@Gagaro
Copy link
Member

Gagaro commented Aug 24, 2020

Unfortunately, importing anything from GeoDjango now also imports the part using gdal, even if we don't use it. So yes you should have it to avoid this error.

@sameergaikwad222
Copy link

sameergaikwad222 commented Oct 4, 2020

You must install Geospatial Libraries (gdal).
Here is the guide for Ubuntu to install same.

https://docs.djangoproject.com/en/3.1/ref/contrib/gis/install/geolibs/

This issue can be closed now.

@jlesech
Copy link
Contributor Author

jlesech commented Oct 4, 2020

Thanks. This dependency should be documented. I created a pull request for that.

@olmerg
Copy link

olmerg commented Dec 1, 2020

I recoomend to downdload the procompiled package from https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal and then add the dll (for windows) in setting.py of your Django project

GDAL_LIBRARY_PATH = r".venv\Lib\site-packages\osgeo\gdal301.dll"
GEOS_LIBRARY_PATH = r".venv\Lib\site-packages\osgeo\geos_c.dll"

@Gilbishkosma
Copy link

This article is useful to setup GDAL
https://www.pointsnorthgis.ca/blog/geodjango-gdal-setup-windows-10/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

5 participants