How to make GDAL for Django Projects on Window
date
Jan 24, 2024
summary
How to make GDAL for Django Projects on Window
slug
how-to-make-gdal-for-django-projects-on-window
status
Published
tags
Python
My Work
GIS
Django
type
Post
Created time
Jan 24, 2024 01:43 PM
URL
Recently I’m studying python and django framework. And a problem encountered while working on a project which created by a my collage is use GDAL library in project. I will be easier if running project on linux / mac osx because gdal just need install via some command like `
sudo apt-get install -y libgdal-dev gdal-bin 
But will really hard if running project on window. I found
pyenv-win to be the right flovar for my purpose, and pyenv-win-env for make isolate environment with virtualenv .TLDR
Step by step
And now with GDAL we can make it easier with
pywin - Step 1 : Create a folder for project like
geo_projectby use commandpython -m venv venvand active it use.\venv\Script\activateIf you usenushelllike me, we can use commandoverlay use .\venv\Scripts\activate.nu
- Step 2 : Install
pipwinuse commandpip install pipwin. This like we are clone person of me. Hahaa =))
- Step 3 : Install
gdaluse simple commandpipwin install gdaland that’s it. Then continue install django usepip install django. Make a project use commanddjango-admin startproject geo-projectand check that everthing is working bypythonmanage.pyrunserver
- Step 4: Install missing dependencies
pip install psycopg2
- Step 5 : Connection with PostgreSQL / PostGIS by config in
settings.pyin database variables
- Step 6 : Define the variable for django can found GDAL path. There is config in
settings.py
Updated: If you like me encounter the problem when connect to postgresql and got the problem with postgis not found. I’m running postgresql like portable and add to Laragon. Please add it to postgresql follow this way :
- Download PostGIS bundle file from web https://postgis.net/documentation/getting_started/install_windows/ and got the download link form https://download.osgeo.org/postgis/windows/. Get a version adapt for your postgresql
- Extract all file content from download zip file and merge to postgresql folder in your window. And that’s all. Good luck