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

ImproperlyConfigured: Could not find the GDAL library when setting up local environment #1223

Open
Samwalton9 opened this issue May 6, 2022 · 4 comments

Comments

@Samwalton9
Copy link

Samwalton9 commented May 6, 2022

Issue and Steps to Reproduce

I've been working on getting WCIVF set up locally, following INSTALL.md. That's mostly worked well except when I come to run python manage.py migrate for the first time. I get the following error:

...
File "C:\Users\samwa\WhoCanIVoteFor\venv\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 46, in
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal302", "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

I'm currently installing GDAL via OSGeo4W, but I'd love to know if I missed a documented step.

@Samwalton9
Copy link
Author

Samwalton9 commented May 6, 2022

I installed GDAL and set GDAL_LIBRARY_PATH = r'C:\OSGeo4W\bin\gdal304.dll'

I'm now getting a new GIS-related error:

File "C:\Users\samwa\WhoCanIVoteFor\venv-64\lib\site-packages\django\db\utils.py", line 122, in load_backend
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.postgis' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'

with the cause being:

File "C:\Users\samwa\WhoCanIVoteFor\venv-64\lib\site-packages\django\contrib\gis\geos\libgeos.py", line 52, in load_geos
raise ImportError(
ImportError: Could not find the GEOS library (tried "geos_c", "libgeos_c-1"). Try setting GEOS_LIBRARY_PATH in your settings.

@Samwalton9
Copy link
Author

Samwalton9 commented May 6, 2022

Setting GEOS_LIBRARY_PATH = r'C:\OSGeo4W\bin\geos_c.dll' solved the new error, and migrations have now completed!

Should INSTALL.md be updated to include the need to install GDAL, or was there something unique about my setup process that broke things?

@Samwalton9
Copy link
Author

I'm now having more GDAL issues while trying to run pytest - I had to go and install the GDAL Python package and am getting stuck on:

File "c:\users\samwa\whocanivotefor\venv-64\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 53, in
lgdal = CDLL(lib_path)
File "C:\Users\samwa\AppData\Local\Programs\Python\Python38-64\lib\ctypes_init_.py", line 373, in init
self._handle = _dlopen(self._name, mode)
OSError: [WinError 127] The specified procedure could not be found

Feeling like I missed something important with setting up GDAL :)

@GeoWill
Copy link
Contributor

GeoWill commented May 6, 2022

I have got Django and gdal to play on Windows in the distant past, but it's not always straight forward.

Have you done the"modify your environment" bits described here: https://docs.djangoproject.com/en/3.2/ref/contrib/gis/install/#modify-windows-environment
Not sure if that will fix it, but maybe. Note the need to restart.

The other approach that might yield results (and let's you maintain different versions in parallel) is to use anaconda, and anaconda environments. That is often a good bet on Windows when dealing with python libraries that bind to C extensions.

It's fair to say it's unlikely this project has been set up on Windows very often, so any tips in the readme will be appreciated.

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

2 participants