0

This comes from the continuation of my question here :

error in GDAL setup command: use_2to3 is invalid

Since the nature of error has changed, its important to post it separately. I'm running Django rest api with the django 3.2 on GCPUbuntu 18.04 LTS. I'm facing a problem when I run docker-compose command. The trace points to Gdal

Because of conflicts between setuptools==67.6.0 and gdal==2.4.2 and causing the previous error in the linked question (which isn't solved), I attempted the following :

I removed gdal package in requirements.txt and used the following :

sudo apt install libgdal-dev
pip3 install GDAL==$(gdal-config --version | awk -F'[.]' '{print $1"."$2}')

The above shows to use legacy setup.py and it recognized gdal-config version to be 2.4 (rather than 2.4.2) and installed it.

Now when I run docker-compose and the containers I get the following :

django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal", "GDAL", "gdal3.1.0", "gdal3.0.0", "gdal2.4.0", "gdal2.3.0", "gdal2.2.0", "gdal2.1.0", "gdal2.0.0"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

setuptools for other packages remains at 67.6.0 while gdal is separately installed (not from requirements.txt) using a legacy installer.

I have already tried :

sudo apt install libgdal-dev --upgrade
sudo apt-get install gdal-bin --upgrade

which are solutions mentioned for user facing a similar problem.

EDIT : Based on recommendation of @phd, Adding GDAL_LIBRARY_PATH to my settings.py after referring to the post : https://github.com/moose46/Jobbee/blob/master/backend/backend/settings.py#L156 https://docs.djangoproject.com/en/4.1/ref/contrib/gis/install/geolibs/#gdal-library-path

Proposed solution :

VIRTUAL_ENV_BASE = os.environ.get("ENVIRONMENT")
GDAL_LIBRARY_PATH = VIRTUAL_ENV_BASE + "/home/earthling/myEnv/lib/python3.8/site-packages/osgeo/gdal304.dll"

However , The following is inside osgeo folder,gdal304.dll isnt there.

osgeo folder inside site-packages

Getting the following trace now after running docker-compose:

OSError: development/home/earthling/myEnv/lib/python3.8/site-packages/osgeo/gdal304.dll: cannot open shared object file: No such file or directory

EDIT : 12/03/2023 After adding

GDAL_LIBRARY_PATH = "/usr/lib/libgdal.so.20.5.2"

Getting the following trace :

my-api-webserver | Traceback (most recent call last):
my-api-webserver |   File "manage.py", line 25, in <module>
my-api-webserver |     execute_from_command_line(sys.argv)
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 419, in execute_from_command_line
my-api-webserver |     utility.execute()
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/core/management/__init__.py", line 395, in execute
my-api-webserver |     django.setup()
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
my-api-webserver |     apps.populate(settings.INSTALLED_APPS)
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
my-api-webserver |     app_config.import_models()
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/apps/config.py", line 301, in import_models
my-api-webserver |     self.models_module = import_module(models_module_name)
my-api-webserver |   File "/usr/local/lib/python3.8/importlib/__init__.py", line 127, in import_module
my-api-webserver |     return _bootstrap._gcd_import(name[level:], package, level)
my-api-webserver |   File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
my-api-webserver |   File "<frozen importlib._bootstrap>", line 991, in _find_and_load
my-api-webserver |   File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
my-api-webserver |   File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
my-api-webserver |   File "<frozen importlib._bootstrap_external>", line 843, in exec_module
my-api-webserver |   File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
my-api-webserver |   File "/opt/my-api/kosmosnetwork_socialcommerce/src/commerce/apps/stores/models.py", line 3, in <module>
my-api-webserver |     from . import abstract_models
my-api-webserver |   File "/opt/my-api/kosmosnetwork_socialcommerce/src/commerce/apps/stores/abstract_models.py", line 1, in <module>
my-api-webserver |     from django.contrib.gis.db.models import Manager, PointField
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
my-api-webserver |     import django.contrib.gis.db.models.functions  # NOQA
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/contrib/gis/db/models/functions.py", line 3, in <module>
my-api-webserver |     from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
my-api-webserver |     from django.contrib.gis import forms, gdal
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
my-api-webserver |     from .fields import (  # NOQA
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
my-api-webserver |     from django.contrib.gis.gdal import GDALException
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
my-api-webserver |     from django.contrib.gis.gdal.datasource import DataSource
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/contrib/gis/gdal/datasource.py", line 40, in <module>
my-api-webserver |     from django.contrib.gis.gdal.driver import Driver
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/contrib/gis/gdal/driver.py", line 5, in <module>
my-api-webserver |     from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/contrib/gis/gdal/prototypes/ds.py", line 9, in <module>
my-api-webserver |     from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal
my-api-webserver |   File "/usr/local/lib/python3.8/site-packages/django/contrib/gis/gdal/libgdal.py", line 50, in <module>
my-api-webserver |     lgdal = CDLL(lib_path)
my-api-webserver |   File "/usr/local/lib/python3.8/ctypes/__init__.py", line 373, in __init__
my-api-webserver |     self._handle = _dlopen(self._name, mode)
my-api-webserver | OSError: /usr/lib/libgdal.so.20.5.2: cannot open shared object file: No such file or directory
my-api-webserver exited with code 1
Earthling
  • 83
  • 3
  • 13
  • "*recognized gdal-config version to be 2.4 (rather than 2.4.2)*" Because that what you output in `awk '{print $1"."$2}'` – phd Mar 09 '23 at 18:00
  • @phd. Thank you for pointing that out. Can you please help me with the issue above if you could ? – Earthling Mar 09 '23 at 18:13
  • May be it needs `GDAL_LIBRARY_PATH="/usr/lib/x86_64-linux-gnu/libgdal.so"` in `settings.py`? https://stackoverflow.com/a/67140709/7976758 Found in https://stackoverflow.com/search?q=django.core.exceptions.ImproperlyConfigured%3A+Could+not+find+the+GDAL+library – phd Mar 09 '23 at 20:49
  • Sure. Will try the above and update. – Earthling Mar 10 '23 at 03:14
  • Hi @phd. Getting this now after updating & running my docker containers : "OSError: /usr/lib/x86_64-linux-gnu/libgdal.so: cannot open shared object file: No such file or directory" – Earthling Mar 10 '23 at 03:33
  • Ah, sorry, my bad, in bionic 18.04 it's [`/usr/lib/libgdal.so`](https://packages.ubuntu.com/bionic/amd64/libgdal-dev/filelist). – phd Mar 10 '23 at 04:11
  • GDAL_LIBRARY_PATH="/usr/lib/libgdal.so" . Getting Same:"OSError: /usr/lib/libgdal.so: cannot open shared object file: No such file or directory". I checked whether the file is there an it is there ! wonder what is wrong. – Earthling Mar 10 '23 at 04:27
  • [That's](https://docs.djangoproject.com/en/4.1/ref/contrib/gis/install/geolibs/#gdal-library-path) it. [Example](https://github.com/moose46/Jobbee/blob/master/backend/backend/settings.py#L156). – phd Mar 10 '23 at 04:36
  • Have updated the quesion pls check. the .dll file isnt there in my folder osgeo – Earthling Mar 10 '23 at 05:11
  • @phd getting the same error. this time with pointing to the dll file – Earthling Mar 10 '23 at 05:22
  • Hello @phd. Any thoughts on what could be done ? – Earthling Mar 10 '23 at 16:41
  • Do you understand that extension `.dll` is for a different OS? That is, the example that I showed was only an example, not a code to blindly copy. You need to find `libgdal.so` at you system; is it `/usr/lib/libgdal.so`? If `GDAL_LIBRARY_PATH="/usr/lib/libgdal.so"` in `settings.py` doesn't help I'm out of ideas. Perhaps there should be a table what version of GDAL to use with what version of GeoDjango so after installing GDAL you need to downgrade Django but I don't know to what version. – phd Mar 10 '23 at 16:50
  • Hi@phd. well I have erred there. I'm a newbie , maybe not a advanced user like you. – Earthling Mar 11 '23 at 16:55
  • GDAL_LIBRARY_PATH = os.path.join("/usr/lib/libgdal.so") is what i tried now. The error that comes is : OSError: /usr/lib/libgdal.so: cannot open shared object file: No such file or directory – Earthling Mar 11 '23 at 17:01
  • You don't need `os.path.join()` with exactly 1 component; `GDAL_LIBRARY_PATH = "/usr/lib/libgdal.so"` is enough. But first — is it there? `ls -l /usr/lib/libgdal.so` in command line. – phd Mar 11 '23 at 17:55
  • HI I got the following result "lrwxrwxrwx 1 root root 17 Jul 14 2019 /usr/lib/libgdal.so -> libgdal.so.20.5.2" – Earthling Mar 12 '23 at 03:10
  • So either `GDAL_LIBRARY_PATH = "/usr/lib/libgdal.so"` or `GDAL_LIBRARY_PATH = "/usr/lib/libgdal.so.20.5.2"` should work. If doesn't work — it's most probably versioning problem: either up/downgrade `libdgal-dev` or GeoDjango. – phd Mar 12 '23 at 04:40
  • Sure. we try out downgrading because even 20.5.2 at the every end gives the same issue. – Earthling Mar 12 '23 at 05:03
  • Updated the question with the detailed trace just for the record. Also i'm looking to downgrade libgdal-dev first and GeoDjango. Any help for the versions would be helpful. – Earthling Mar 12 '23 at 06:09
  • I'm currently on Ubuntu 18.04. would upgrading Ubuntu to 22.04 work. Here is the list of libgdal-dev packages. https://pkgs.org/download/libgdal-dev – Earthling Mar 12 '23 at 10:49
  • I upgraded to ubuntu 22.05 LTS. now gdal config --version == 3.4.1 and so is the package gdal installed through pip. Getting the same "OSError: /usr/lib/libgdal.so: cannot open shared object file: No such file or directory" – Earthling Mar 12 '23 at 14:32
  • @phd have uploaded it as a separate question. https://stackoverflow.com/questions/75718063/oserror-usr-lib-libgdal-so-cannot-open-shared-object-file-no-such-file-or-di – Earthling Mar 13 '23 at 11:30
  • Hi @phd. Could you help me here if possible: https://stackoverflow.com/questions/75733558/django-db-utils-notsupportederror-extension-postgis-is-not-available – Earthling Mar 15 '23 at 13:57

0 Answers0