I\'ve been trying to setup my windows computer such that I can have a local postgreSQL with PostGIS extension. With this installed I hope to be able to create a project with
Just to follow up on the nice and detailed answer of Udi (cannot comment directly as my rep is under 50, it is the answer marked as the most useful);
After many hours I tried his offered solution which also did not work for me. I was getting the following error:
OSError: [WinError 193] %1 is not a valid Win32 application
But I stayed there and found out that although I'm running 64 python and operating system (for sure), it kept looking for 32 bit (OSGeo4W
) folder. What eventually let me pass was to copy contents of the OSGeo4W64
folder to the OSGeo4W
. Hope it will save you time.
One more note:
Be sure that you edit libgdal.py
file in your environment folder. It may exist in more than one place - your python folder and environment folder - if you edit the libgdal
in your python dir, it is not going to work.
After updating some OSGEO4W on my Windows 10 Pro machine I started having problems with the GDAL bindings again. I previously used a combination of the solutions posted here and with this tutorial.
This is what works for me using Windows 10 Pro 64-bit, Django 3.0.6 and GDAL 3.0.4 using a python 3.7 virtual environment. I have tested it without OSGEO4W and it seems to work.
First, download the GDAL wheel from Christoph Gohlke's Unofficial Windows Binaries for Python Extension Packages.
pip install "/path/to/GDAL‑3.0.4‑cp37‑cp37m‑win_amd64.whl"
Modify the libgdal.py file in the virtual envrironment site packages by adding 'gdal300' to line 23 of the Django GDAL package python file (/path/to/virtual_env/Lib/site-packages/django/contrib/gis/gdal/libgdal.py):
elif os.name == 'nt':
# Windows NT shared libraries
lib_names = ['gdal300', 'gdal204', 'gdal203', 'gdal202', 'gdal201', 'gdal20']
Finally, in your settings.py file in your Django project add
if os.name == 'nt':
VENV_BASE = os.environ['VIRTUAL_ENV']
os.environ['PATH'] = os.path.join(VENV_BASE, 'Lib\\site-packages\\osgeo') + ';' + os.environ['PATH']
os.environ['PROJ_LIB'] = os.path.join(VENV_BASE, 'Lib\\site-packages\\osgeo\\data\\proj') + ';' + os.environ['PATH']