0

I am trying to install GeoDjango what turns out to be much harder than I thought. After I installed the OSGeo4W on my 64 Bit Windows 10 system I set everything up in the settings.py file but now I get this error:

FileNotFoundError: Could not find module 'C:\OSGeo4W\bin\gdal304.dll' (or one of its dependencies). Try using the full path with constructor syntax.

I also set the GDAL_LIBRARY_PATH but it just won't work.

GDAL_LIBRARY_PATH = "C:\\OSGeo4W\\bin\\gdal304.dll"

This is my C:\OSGeo4W\bin path and as you can see the gdal304.dll file is there

Image of the folder

My Python is on version 3.10.6 Django is on version 4.1

I already tried to solve it by myself for a week but slowly I have no idea left on what to do

Henrik
  • 828
  • 8
  • 34

2 Answers2

1

Update: 03.04.2023

As of today Django 4.2 is released. One change is support for newer GDAL version. See list: here

OSGeo4W does now also distribute a new gdal305.dll library. Therefore I gave it a shot & installed a fresh OSGeo4W with GoeDjango 4.2.

This worked out of the box. My recommendation at this point, upgrade as soon as possible to Django 4.2 and update you OSGeo4W. With this, none of the hacks below are necessary any more.


Old Comment (Prior 03.04.2023):

I ran into this problem too, since I updated my old GEO Django Setup today.

You may use a Docker Image as suggested by the others, but I prefere a native solution, since I don't want to spin up Docker every time I start coding.

Your solution is in the brackets: (or one of its dependencies)

You may look up the transitive dependendencies from gdal304.dll. There are several tools for this (see here). I'm using here now the Git integrated MinGW - Shell that has ldd installed. This should be the case for any (newer) Git installation on Windows.

enter image description here

As you can see, some dependencies are already fullfilled from your operating system. Others that are missing, have to be fullfilled from OSGeo4W. If you compare this with your bin directory from OSGeo4W you will see the Problem:

enter image description here

Sadly a simple "renaming" does not the trick. I was lucky and had not yet deleted my old OSGeo4W version. In the old files I then found the necessary DLL.

enter image description here

So, long story short: You need the jpeg.dll file.

There are sites like "windll.com" or "dll-files.com", but I would not recommend using them. I don't trust these sites. You may install something like "MSYS2", "Cygwin" or even "MVSC", install the "libjpeg-turbo" library and then finally copy & paste the necessary DLL file.

This is also suggested on the official Site for libjpeg-turbo: https://libjpeg-turbo.org/Documentation/OfficialBinaries

But this seems like a lot of work for someone who just want to have the DLL file, but then again: Never download a library blindly from the Internet and load it into your application. These libraries could do anthing!

SimpleJack
  • 167
  • 1
  • 8
  • Wow! Thanks for the detailed answer. What I did: I just switched from SQLite to MySQL which has very strong geo-features build in. Way faster but I have to deal with raw sql :) Thanks for your help anyway! – Henrik Oct 31 '22 at 14:12
1

Here's my hacky workaround and I hope it helps someone. After trying hunt for a clean jpeg.dll file as per the answer from @SimpleJack, using MINGW, CYGWIN installers, I gave up after not finding it.

Now, after you have fully installed OSGeo4W, you'll see gdal30x.dll in the bin folder. What I just did is rename gdal304.dll to something else, say gdal304.dll.orig so that it is completely skipped.

Django proceeded to work when that broken file was not found on the system.

enter image description here

Shailen
  • 7,909
  • 3
  • 29
  • 37
  • Thank you for your reply. I just switched to MySQL and dumped Sqlite and GeoDjango. Thank you for your help anyways :) – Henrik Mar 29 '23 at 19:52