Zachary Deziel
Zachary Deziel

Reputation: 94

How to configure geodjango on windows10?

I am working on a geodjango project on windows-10. I have been following the tutorial and the installation guide from the geodjango documentation. I have installed all required packages and executed the bat script.

Python version: Python 3.7.4 (tags/v3.7.4:e09359112e, Jul 8 2019, 20:13:57) [MSC v.1916 64 bit (AMD64)]

OSGEO version: GDAL 2.4.1, released 2019/03/15

Initially I had to reconfigure my virtual environment to have a 64-bit python version matching that of the OSGEOW4 application.

I've tried the solutions answered for questions 1 and 2.

Those solutions include:

I have not yet tried the alternative of installing the gdal from a binary file. I do not understand why I would not be able to configure with the OSGEO application.

The error present in the command prompt when executing python manage.py check is:

Traceback (most recent call last):
  File "manage.py", line 21, in <module>
    main()

[...]

OSError: [WinError 126] The specified module could not be found

Seems like it is an issue that many encounter.

A concise yet complete answer would be greatly appreciated.

Thanks for the help.

Upvotes: 1

Views: 791

Answers (2)

ArtSav
ArtSav

Reputation: 162

The easiest way I've found is:

  1. Install Gdal from whl, for examle: [https://www.lfd.uci.edu/~gohlke/pythonlibs/][1], if this link unavailable, the whl you need is not so difficult to find.
  2. Add to settings.py this code (change name of virtualenv if need):
       OSGEO_VENV = Path(__file__).parents[1] / 'venv/Lib/site-packages/osgeo/'
       GEOS_LIBRARY_PATH = str(OSGEO_VENV / 'geos_c.dll')
       GDAL_LIBRARY_PATH = str(OSGEO_VENV / 'gdal204.dll')
       os.environ["PATH"] += os.pathsep + str(OSGEO_VENV)```   
    

if previously installed OSGeo, make sure to clean path variables.

Upvotes: 2

Zachary Deziel
Zachary Deziel

Reputation: 94

I ended up downloading the binary GDAL file from this link. The version that worked for my Python version was GDAL-2.4.1-cp37-cp37m-win32.

Some key points if you are stumbling upon the same issue:

  • Make sure the python version in your virtual environment is the same bit size as the gdal version

  • to enable execution of .bat scripts you must change the Set-ExecutionPolicy variable

The steps of my configuration are the following:

  1. Download postgres with postgis spatial extension from edm
  2. Create Django project with a specific environment
  3. Open powershell and navigate to Django project environment directory
cd .../your-venv/
  1. Set the execution policy variable
Set-ExecutionPolicy -ExecutionPolicy RemoteSigned
  1. Activate the environment:
Scripts/Activate.ps1
  1. Download the appropriate gdal version for your environment (https://www.lfd.uci.edu/~gohlke/pythonlibs/)
  2. Install gdal from binaries in your venv:
pip install C:\...\GDAL-2.4.1-cp37-cp37m-win32.whl
  1. Install any other requirements for your project

Hope this helps.

Upvotes: 2

Related Questions