Problem installing GeoDjango on Windows 10 with OSGeo4W: qlite3_column_origin_name could not be located in the dynamic link library

2,818 views
Skip to first unread message

Oliver Larcher

unread,
Nov 28, 2018, 7:17:57 AM11/28/18
to geodjango
Hi,

could someone please help me with an installation issue on Windows 10 (64bit)?
I tried installing GD according to the official guide: https://docs.djangoproject.com/en/2.1/ref/contrib/gis/install/#installation using OSGeo4W (64bit)
Environment variables are set and working. Django is installed in a virtual environment (python 3.6.6), Django 2.1.

When I do import django.contrib.gis.geos I get OSError: [WinError 127] The specified procedure could not be found.
When i run manage.py makemigrations I get a popup error: (python.exe): The procedure entry point sqlite3_column_origin_name could not be located in the dynamic link library C:\OSGeo4W64

Thought it may be related to this issue, but the solution did not work for me.

Any help would be appreciated, thanks!
Oliver

Mark Van Hoeven

unread,
Nov 28, 2018, 9:36:18 AM11/28/18
to geod...@googlegroups.com
I successfully got this working earlier in the year and found my notes to myself, as follows. I happen to be using the Bitnami Django Stack, that's why my directories look like this. I went to the following link to grab something that was appropriate to the Python version in the stack. You'll adapt the version and the paths to your own situation.


Wherever the file is downloaded, right-click to bring up the win shell and paste this in:

python -m pip install GDAL-2.2.3-cp36-cp36m-win32.whl
It installs everything under:

C:\Bitnami\djangostack-2.0.2-2\python\Lib\site-packages\osgeo
Make sure to go to the win environment paths and add:

GDAL_DATA = C:\Bitnami\djangostack-2.0.2-2\python\Lib\site-packages\osgeo\data\gdal
GDAL_DIVER_PATH = C:\Bitnami\djangostack-2.0.2-2\python\Lib\site-packages\osgeo\gdalplugins

--
You received this message because you are subscribed to the Google Groups "geodjango" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geodjango+...@googlegroups.com.
To post to this group, send email to geod...@googlegroups.com.
Visit this group at https://groups.google.com/group/geodjango.
For more options, visit https://groups.google.com/d/optout.


--
Mark Van Hoeven
Owner, Data Halo, LLC

Oliver Larcher

unread,
Nov 28, 2018, 6:04:07 PM11/28/18
to geod...@googlegroups.com
Mark, you are my hero, that actually solved the problem!
Though I'm not sure if there might be a typo in GDAL_DIVER_PATH? Shouldn't it be  GDAL_DRIVER_PATH?

Anyway, thank ypu very much!

Theo

unread,
Mar 4, 2019, 2:01:42 AM3/4/19
to geodjango
Worked for me too on windows 10 and python 3.6.3,.

Thank you Mark

Stathis Angelou

unread,
Feb 15, 2021, 7:57:04 AM2/15/21
to geodjango
Good morning all, 

I hope everyone is well in these interesting times,

I was quite happy to find this thread as i am experiencing a similar issue,

following Mark's  instructions i managed to progress a bit (thank you Mark for this very much)

So i managed to download and install GDAL using the link Mark provided and added the the two user variables for GDAL_DATA and GDAL_DRIVER_PATH but i still get the same error: " The procedure entry point sqlite3_column_origin_name could not be located in the dynamic link library C:\OSGEO4W64\bin\gdal301.dll 

I am using python 3.8.6 on windows server 2016, any advice would be really appreciated.

Kind Regards

Stathis

Theo

unread,
Feb 15, 2021, 10:39:17 AM2/15/21
to geodjango
Hey Stathis,

Could it be something with the database requirements?

https://docs.djangoproject.com/en/3.1/ref/contrib/gis/install/#spatial-database

All the best,
Theo

Stathis Angelou

unread,
Feb 15, 2021, 2:00:59 PM2/15/21
to geodjango
Good afternoon Theo and thank you for your reply, 

I am using PostgreSQL11 so there shouldn't be an issue


I did find this post  online:


Which did resolve some elements but the error still remains

Thank you very much again

Stathis

Vladimir Stupar

unread,
Feb 16, 2021, 3:03:35 AM2/16/21
to geod...@googlegroups.com
Hi Stathis,

I also had a hard time making GeoDjango work on my Windows 10 machine, but eventually, I succeeded.

A lot of the mess is caused by incompatible libraries so you should check your dependencies first at https://docs.djangoproject.com/en/2.2/ref/contrib/gis/install/geolibs/.

I am running Django 2.2 on Python 3.7 with PostGis 2.5 so I first downloaded GDAL 2.4.1 from https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal and installed it into my virtual environment via pip.

Then I installed geo libraries via OSGEO4W bundle.
Set your system variables (assuming that you've installed OSGEO4W to the root:

OSGEO4W_ROOT=C:\OSGeo4W64

GDAL_DATA=%OSGEO4W_ROOT%\share\gdal

PROJ_LIB=%OSGEO4W_ROOT%\share\proj

PATH=%PATH%;%PYTHON_ROOT%;%OSGEO4W_ROOT%\bin


Then additionally, also using OSGEO4W bundle, install GDAL backward compatibility package for your GDAL version (e.g. if you installed GDAL 2.4.1 with pip, then you'd want to install gdal204.dll package).

After that, in the folder Lib\site-packages\django\contrib\gis\gdal of your virual environment look for the file libgdal.py, and add 'gdal204' (or whatever version your GDAL is) in the variable 'lib_names'.

Then in the settings.py of your Django project add a line:

GDAL_LIBRARY_PATH = r'<path_to_your-virtual_environment>\Lib\site-packages\osgeo\gdal204.dll'


In the end, you should copy files from C:\Program Files\PostgreSQL\X.Y\gdal-data to C:\OSGeo4W64\share\gdal and after that it should work.

To be honest, there were a lot of combinations until I made it running so I am not sure anymore if all these steps were really needed, but it works and that is all that matters :)

Let me know how It went.

All the best,
Vlado



--
Vladimir Stupar

Stathis Angelou

unread,
Feb 17, 2021, 6:45:22 AM2/17/21
to geodjango
Good morning Vlado and thank you very much for your email and in-depth solution,

apologies for my delayed response as i wanted to make sure it works for me,

so: - I am running postGIS 2.5 for PG11

 - my GDAL version is 3.2.1

- I have added the mentioned libraries in environment variables on windows

- libgdal.py under Wndows NT shared libraries contains :
 # Windows NT shared libraries
    lib_names = ['gdal301', 'gdal300', 'gdal204', 'gdal203', 'gdal202', 'gdal201', 'gdal20']

- added GDAL_LIBRARY_PATH in django project


Still the error persists, i'm sure i'm missing something.


Thank you very much again

Stathis

Vladimir Stupar

unread,
Feb 17, 2021, 7:56:49 AM2/17/21
to geod...@googlegroups.com
Hi Stathis,

You didn't say what version of Django you're running. Anyway, looks like even the newest version of Django doesn't support GDAL 3.2.1 as per https://docs.djangoproject.com/en/3.2/ref/contrib/gis/install/geolibs/

So, I would first recommend that you install an earlier version of GDAL depending on your Django version.

But, assuming that you installed GDAL 3.2.1 over the:

python -m pip install GDAL‑3.2.1‑cp38‑cp38‑win_amd64.whl (be sure to run this command from your virtual environment directory containing the python.exe script),


you still need to add 'gdal302' to your lib_names variable, so make sure to try this first.


If this doesn't work then you should try with a different version of GDAL.


Let me know how did it go,


All the best,

Vlado




--
Vladimir Stupar

garyd...@gmail.com

unread,
Feb 17, 2021, 8:52:11 AM2/17/21
to geodjango
This may not be your issue but the list lib_names doesn't have a gdal version 3.2.1 in it, try adding 'gdal302' also I use osgeo gdal with the python bindings installed my system env variable look like this

GDAL_LIBRARY_PATH = C:\ProgramData\Anaconda3\envs\geodjango\Lib\site-packages\osgeo
GDAL_DATA = C:\ProgramData\Anaconda3\envs\geodjango\Lib\site-packages\osgeo\data\gdal

not sure if this will help you it has been awhile since I had this problem.

garyd...@gmail.com

unread,
Feb 17, 2021, 8:52:15 AM2/17/21
to geodjango
add ''gdal302' to the list of lib_names.

On Wednesday, February 17, 2021 at 5:45:22 AM UTC-6 staka...@gmail.com wrote:

Stathis Angelou

unread,
Feb 18, 2021, 6:28:24 AM2/18/21
to geodjango
Good morning all and thank you for your messages, i really appreciate your help in this

as suggested i downgraded my GDAL and python version, as Vlado correctly suggested and added gdal302 in the lib names.
I now run:
python 3.6
GDAL 3.1.4
django 3.1.6

but when i runserver in cmd i get the same error  regarding gdal301.dll followed by :

AppData\Local\Programs\Python\Python36\lib\ctypes\__init__.py", line 344, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 127] The specified procedure could not be found

Which is related to the script below found in _init_.py

  Calling the functions releases the Python GIL during the call and
    reacquires it afterwards.
    """
    _func_flags_ = _FUNCFLAG_CDECL
    _func_restype_ = c_int

    def __init__(self, name, mode=DEFAULT_MODE, handle=None,
                 use_errno=False,
                 use_last_error=False):
        self._name = name
        flags = self._func_flags_
        if use_errno:
            flags |= _FUNCFLAG_USE_ERRNO
        if use_last_error:
            flags |= _FUNCFLAG_USE_LASTERROR

        class _FuncPtr(_CFuncPtr):
            _flags_ = flags
            _restype_ = self._func_restype_
        self._FuncPtr = _FuncPtr

        if handle is None:
            self._handle = _dlopen(self._name, mode)
        else:
            self._handle = handle

    def __repr__(self):
        return "<%s '%s', handle %x at %#x>" % \
               (self.__class__.__name__, self._name,
                (self._handle & (_sys.maxsize*2 + 1)),
                id(self) & (_sys.maxsize*2 + 1))

    def __getattr__(self, name):
        if name.startswith('__') and name.endswith('__'):
            raise AttributeError(name)
        func = self.__getitem__(name)
        setattr(self, name, func)
        return func

    def __getitem__(self, name_or_ordinal):
        func = self._FuncPtr((name_or_ordinal, self))
        if not isinstance(name_or_ordinal, int):
            func.__name__ = name_or_ordinal
        return func

class PyDLL(CDLL):


Thank you very much again

Stathis

Vladimir Stupar

unread,
Feb 18, 2021, 7:28:25 AM2/18/21
to geod...@googlegroups.com
Did you changed your GDAL_LIBRARY_PATH to:
GDAL_LIBRARY_PATH = r'<path_to_your-virtual_environment>\Lib\site-packages\osgeo\gdal301.dll'





--
Vladimir Stupar

Stathis Angelou

unread,
Feb 19, 2021, 9:33:08 AM2/19/21
to geodjango
Good afternoon Vlado and thank you for your email,

Yes i did change the path, but i am getting the same error message

Thank you very much again 

Stathis


Vladimir Stupar

unread,
Feb 19, 2021, 2:22:18 PM2/19/21
to geod...@googlegroups.com
Sorry Stathis, but in order to be able to help you I need to have complete overview of your problem.

Can you post:
- pip freeze of your virtual environment,
- spatial dependencies used by your project (psql into your spatial database and then execute SELECT PostGIS_full_version();)
- values of your system variables: Path, GDAL_DATA and PROJ_LIB
- the exact value of GDAL_LIBRARY_PATH variable from Django settings
- GDAL version in OSGeo4W (run gdalinfo --version from OSGeo4w shell)
- and last but not least, send the complete error message, without your explanations.

Good luck,
Vlado



--
Vladimir Stupar

Stathis Angelou

unread,
Feb 20, 2021, 11:31:17 AM2/20/21
to geodjango
Good afternoon Vlado and thank you for your email and great assistance in helping me resolving this issue, honestly i really do appreciate it.

Please see the information below i hope this gives all the answers to your questions 

On Friday, February 19, 2021 at 7:22:18 PM UTC Vlado wrote:
Sorry Stathis, but in order to be able to help you I need to have complete overview of your problem.

Can you post:
- pip freeze of your virtual environment,
asgiref==3.3.1
Django==3.1.7
pytz==2021.1
sqlparse==0.4.1 


- spatial dependencies used by your project (psql into your spatial database and then execute SELECT PostGIS_full_version();)

POSTGIS="2.5.3 r17699" [EXTENSION] PGSQL="110" GEOS="3.7.2-CAPI-1.11.0 3.7.2" PROJ="Rel. 4.9.3, 15 August 2016" GDAL="GDAL 2.2.4, released 2018/03/19 GDAL_DATA not found" LIBXML="2.7.8" LIBJSON="0.12" LIBPROTOBUF="1.2.1" (core procs from "2.5.2 r17328" need upgrade) TOPOLOGY (topology procs from "2.5.2 r17328" need upgrade) RASTER (raster procs from "2.5.2 r17328" need upgrade)
 
- values of your system variables: Path, GDAL_DATA and PROJ_LIB
GDAL
C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Lib\site-packages\django\contrib\gis\gdal
 
- the exact value of GDAL_LIBRARY_PATH variable from Django settings
C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Lib\site-packages\osgeo
 
- GDAL version in OSGeo4W (run gdalinfo --version from OSGeo4w shell) 
 
GDAL 3.1.4, released 2020/10/20
 
- and last but not least, send the complete error message, without your explanations.


C:\Users\sangelrd\projects\mymap>python manage.py makemigrations Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute() File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 377, in execute django.setup() File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\registry.py", line 114, in populate app_config.import_models() File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 978, in _gcd_import File "<frozen importlib._bootstrap>", line 961, in _find_and_load File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 655, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\auth\models.py", line 2, in <module> from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\auth\base_user.py", line 48, in <module> class AbstractBaseUser(models.Model): File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\base.py", line 122, in __new__ new_class.add_to_class('_meta', Options(meta, app_label)) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\base.py", line 326, in add_to_class value.contribute_to_class(cls, name) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\options.py", line 206, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\__init__.py", line 28, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\utils.py", line 214, in __getitem__ backend = load_backend(db['ENGINE']) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\utils.py", line 111, in load_backend return import_module('%s.base' % backend_name) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\backends\spatialite\base.py", line 10, in <module> from .features import DatabaseFeatures File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\backends\spatialite\features.py", line 1, in <module> from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\backends\base\features.py", line 3, in <module> from django.contrib.gis.db import models File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\models\__init__.py", line 3, in <module> import django.contrib.gis.db.models.functions # NOQA File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\models\functions.py", line 3, in <module> from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\models\fields.py", line 3, in <module> from django.contrib.gis import forms, gdal File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\forms\__init__.py", line 3, in <module> from .fields import ( # NOQA File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\forms\fields.py", line 2, in <module> from django.contrib.gis.gdal import GDALException File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\gdal\__init__.py", line 28, in <module> from django.contrib.gis.gdal.datasource import DataSource File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\gdal\datasource.py", line 39, in <module> from django.contrib.gis.gdal.driver import Driver File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\gdal\driver.py", line 5, in <module> from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\gdal\prototypes\ds.py", line 9, in <module> from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 50, in <module> lgdal = CDLL(lib_path) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\ctypes\__init__.py", line 344, in __init__ self._handle = _dlopen(self._name, mode) OSError: [WinError 127] The specified procedure could not be found C:\Users\sangelrd\projects\mymap>python manage.py makemigrations Traceback (most recent call last): File "manage.py", line 22, in <module> main() File "manage.py", line 18, in main execute_from_command_line(sys.argv) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line utility.execute() File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\core\management\__init__.py", line 377, in execute django.setup() File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\__init__.py", line 24, in setup apps.populate(settings.INSTALLED_APPS) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\registry.py", line 114, in populate app_config.import_models() File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\apps\config.py", line 211, in import_models self.models_module = import_module(models_module_name) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "<frozen importlib._bootstrap>", line 978, in _gcd_import File "<frozen importlib._bootstrap>", line 961, in _find_and_load File "<frozen importlib._bootstrap>", line 950, in _find_and_load_unlocked File "<frozen importlib._bootstrap>", line 655, in _load_unlocked File "<frozen importlib._bootstrap_external>", line 678, in exec_module File "<frozen importlib._bootstrap>", line 205, in _call_with_frames_removed File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\auth\models.py", line 2, in <module> from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\auth\base_user.py", line 48, in <module> class AbstractBaseUser(models.Model): File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\base.py", line 122, in __new__ new_class.add_to_class('_meta', Options(meta, app_label)) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\base.py", line 326, in add_to_class value.contribute_to_class(cls, name) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\models\options.py", line 206, in contribute_to_class self.db_table = truncate_name(self.db_table, connection.ops.max_name_length()) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\__init__.py", line 28, in __getattr__ return getattr(connections[DEFAULT_DB_ALIAS], item) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\utils.py", line 214, in __getitem__ backend = load_backend(db['ENGINE']) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\db\utils.py", line 111, in load_backend return import_module('%s.base' % backend_name) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\importlib\__init__.py", line 126, in import_module return _bootstrap._gcd_import(name[level:], package, level) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\backends\spatialite\base.py", line 10, in <module> from .features import DatabaseFeatures File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\backends\spatialite\features.py", line 1, in <module> from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\backends\base\features.py", line 3, in <module> from django.contrib.gis.db import models File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\models\__init__.py", line 3, in <module> import django.contrib.gis.db.models.functions # NOQA File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\models\functions.py", line 3, in <module> from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\db\models\fields.py", line 3, in <module> from django.contrib.gis import forms, gdal File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\forms\__init__.py", line 3, in <module> from .fields import ( # NOQA File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\forms\fields.py", line 2, in <module> from django.contrib.gis.gdal import GDALException File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\gdal\__init__.py", line 28, in <module> from django.contrib.gis.gdal.datasource import DataSource File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\gdal\datasource.py", line 39, in <module> from django.contrib.gis.gdal.driver import Driver File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\gdal\driver.py", line 5, in <module> from django.contrib.gis.gdal.prototypes import ds as vcapi, raster as rcapi File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\gdal\prototypes\ds.py", line 9, in <module> from django.contrib.gis.gdal.libgdal import GDAL_VERSION, lgdal File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 50, in <module> lgdal = CDLL(lib_path) File "C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\lib\ctypes\__init__.py", line 344, in __init__ self._handle = _dlopen(self._name, mode) OSError: [WinError 127] The specified procedure could not be found  

Good luck,
Vlado


Thank you very very much again

Vladimir Stupar

unread,
Feb 23, 2021, 4:17:09 PM2/23/21
to geod...@googlegroups.com
Hi Stathis.

Ok, from your pip freeze it looks you didn't install GDAL to your virtual environment. I explained the procedure in my first and second post. Only after that you will have osgeo folder with gdal301.dll in it inside \Lib\site-packages\  folder of your virtual environment.

Then, your GDAL_LIBRARY_PATH inside settings.py should look like:
GDAL_LIBRARY_PATH = r'<path_to_your-virtual_environment>\Lib\site-packages\osgeo\gdal301.dll'
What you have now is not good, because the path is not the one of your virtual environment.

Also, set GDAL_DATA and PROJ_LIB system variables to:  C:\OSGeo4W6\share\gdal and C:\OSGeo4W6\share\proj assuming you installed OSGeo4W to the root of C:

At the end don't forget to copy missing files form C:\Program Files\PostgreSQL\X.Y\gdal-data to C:\OSGeo4W64\share\gdal.

All the best,
Vlado

P.S. How come you don't have psycopg2 installed?



--
Vladimir Stupar

Stathis Angelou

unread,
Feb 25, 2021, 10:26:18 AM2/25/21
to geodjango
Good afternoon Vlado and thank you very much for your time, input and feedback in this, I really do appreciate it beyond words.

I had some further development over the weekend following your previous post:

- so the pip freeze of my virtual environment is:
(mymap) C:\Users\sangelrd\projects\mymap>pip freeze
asgiref==3.3.1
Django==3.1.7
GDAL @ file:///C:/Users/sangelrd/projects/mymap/GDAL-2.4.1-cp36-cp36m-win_amd64.whl
psycopg2==2.8.6
pytz==2021.1
spatialite==0.0.3
sqlparse==0.4.1

- i have imported in settings.py 

import os
if os.name == 'nt':
    import platform
    OSGEO4W = r"C:\OSGeo4W"
    if '64' in platform.architecture()[0]:
        OSGEO4W += "64"
    assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
    os.environ['OSGEO4W_ROOT'] = OSGEO4W
    os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
    os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
    os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']
    os.environ['GDAL_LIBRARY_PATH'] = r"\apps\Python36\Lib\site-packages\osgeo\gdal301.dll"

-also in user variables in windows i have the variables below:

GDAL_DATA  %OSGEO4W_ROOT%\share\gdal
GDAL_LIBRARY_PATH %OSGEO4W_ROOT%\apps\Python36\Lib\site-packages\osgeo
OSGEO4W_ROOT C:\OSGeo4W64
PATH C:\Windows;C:\Windows\System32;C:\OSGeo4W64\apps\Python36\;C:\OSGeo4W64\apps\Python36\Scripts
PROJ_LIB %OSGEO4W_ROOT%\share\proj
PYTHON_PATH C:\OSGeo4W64\apps\Python36\Lib\site-packages;C:\OSGeo4W64\apps\Python36\Lib;C:\OSGeo4W64\apps\Python36\Lib\site-packages\osgeo

- finally i have copied the missing files from \gdal-data to   C:\OSGeo4W64\share\gdal

I still get the same error so definitely i am still missing something,

Thank you very much again for your help

Stathis

Stathis Angelou

unread,
Mar 9, 2021, 6:49:31 AM3/9/21
to geodjango
Good morning all, 

I hope everyone is well, having spend the past week trying numerous solutions as suggested in this group, as well as online sources, in the end i just renamed gdal301.dll to gdal301a.dll and it worked :)

As Vlado mentioned, because i did try quite a few things, i am not quite sure as to what was the actual solution to my problem

Thank you everyone for your help, i am really grateful

Stay safe

Stathis

Vladimir Stupar

unread,
Mar 10, 2021, 7:00:19 AM3/10/21
to geod...@googlegroups.com
Dear Stathis,

Sorry I didn't answer earlier, but from your mail before this one (Feb 25) it looks like you messed up dependencies and environments. This is also backed up by the new thread you opened where your application can not find rtree module.

So, first of all, instead of OSGeo4W Python installation, you should start with your global Python, which is used when you are making your virtual environment, and which should be installed in your root directory. Something like 'C:\Python36' and not the version from OSGeo4W which is in "C:\OSGeo4W64\apps\Python36".

Because of this, you should modify your system paths accordingly:
- add C:\Python36\;C:\Python36\Scripts to PATH and remove all OSGeo4W64 versions of Python
   Note that here you should have also the path to you Postgres bin folder, something like "C:\Program Files\PostgreSQL\11\bin", so add this too if you didn't already.
- add  C:\Python36\Lib\site-packages;C:\Python36\Lib;C:\Python36\Lib\site-packages\osgeo to PYTHON_PATH
- remove the gdal library path: GDAL_LIBRARY_PATH %OSGEO4W_ROOT%\apps\Python36\Lib\site-packages\osgeo
   Here, you were telling the app that your gdal is 3.1 and it is in OSGeo folder, while you want to use gdal 2.4.1 (gdal204.dll) which you installed over pip in your virtual environment, and gdal204.dll should be located in "C:\Users\sangelrd\projects\mymap\Lib\site-packages\osgeo", assuming this is the path to your virtual environment "mymap". But take care!, you need the path to your virtual environment "mymap" and not your project "mymap". Also it is very important that you installed GDAL2.4.1 form inside your virtual environment "mypy" folder where your python.exe script is, and not from your projects folder (i.e. C:/Users/sangelrd/projects/mymap). If you are not sure, the easiest way to check the path of your working virtual environment is to run:
>>> import os
>>> os.environ['VIRTUAL_ENV']

from inside your virtual environment "mymap".
When yyou are sure about the path to your virtual environemnt, use this path to install GDAL-2.4.1, if you didn't already.

After this, remove all


if os.name == 'nt':
    import platform
    OSGEO4W = r"C:\OSGeo4W"
    if '64' in platform.architecture()[0]:
        OSGEO4W += "64"
    assert os.path.isdir(OSGEO4W), "Directory does not exist: " + OSGEO4W
    os.environ['OSGEO4W_ROOT'] = OSGEO4W
    os.environ['GDAL_DATA'] = OSGEO4W + r"\share\gdal"
    os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj"
    os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']
    os.environ['GDAL_LIBRARY_PATH'] = r"\apps\Python36\Lib\site-packages\osgeo\gdal301.dll"

code from your settings file, and just add:
GDAL_LIBRARY_PATH = r'path_to_your_virtual_environment\Lib\site-packages\osgeo\gdal204.dll'

where the "path_to_your_virtual_environment" part is what was returned by 
>>> import os
>>> os.environ['VIRTUAL_ENV']

command you executed earlier.

So, regarding the OSGEO4W, you just need to use its "share" folder with paths to gdal and proj folders, where you will at the end copy the missing filed from PG gdal-data to C:\OSGeo4W64\share\gdal (I think you've already done this part).
Remove all other references to OSGeo4W from your system variables and your code.
If you folow all these steps, there should be no problems with your application, and your app will also know where to find Rtree module.
Send us info of what you've done.
All the best, Vlado



--
Vladimir Stupar

Stathis Angelou

unread,
Mar 12, 2021, 7:57:33 PM3/12/21
to geodjango
Good evening Vlado and thank you for your email and suggestions. You are absolutely right in terms of dependencies and environments, but understandable for a first timer i guess.

So following your suggestions, and thank you for that  i have "moved" my virtual environment and changed all paths to :

GDAL_DATA: C:\OSGeo4W64\share\gdal;C:\Users\sangelrd\Envs\mymap\Lib\site-packages\osgeo;C:\Users\sangelrd\Envs\mymap\Lib\site-packages
GDAL_DRIVER_PATH: C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Lib
GDAL_LIBRARY_PATH: C:\OSGeo4W64\share\proj; C:\OSGeo4W64\share\gdal; C:\OSGeo4W64\bin\gdal204.dll;C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Lib\site-packages\django\contrib\gis\gdal;C:\Users\sangelrd\envs\mymap\lib\site-packages
GEOS_LIBRARY_PATH: C:\OSGeo4W64\bin\geos_c.dll
PATH: C:\Users\sangelrd\AppData\Local\Programs\Python\Python36;C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Scripts;C:\Program Files\PostgreSQL\11\bin

My virtual environment is now:
C:\Users\sangelrd\Envs\mymap

Pip freeze
C:\Users\sangelrd\projects\mymap>pip freeze
appdirs==1.4.4
asgiref==3.3.1
certifi==2020.12.5
distlib==0.3.1
Django==3.1.6
filelock==3.0.12
GDAL @ file:///C:/Users/sangelrd/Envs/mymap/GDAL-2.4.1-cp36-cp36m-win_amd64.whl
importlib-metadata==3.4.0
importlib-resources==5.1.0
osgeo==0.0.0
pbr==5.5.1
pipenv==2020.11.15
pytz==2021.1
Rtree==0.9.7
six==1.15.0
spatialite==0.0.3
sqlparse==0.4.1
stevedore==3.3.0
typing-extensions==3.7.4.3
virtualenv==20.4.2
virtualenv-clone==0.5.4
virtualenvwrapper==4.8.4
virtualenvwrapper-win==1.2.6
zipp==3.4.0

my settings file had all code removed and now only has 

GDAL_LIBRARY_PATH = r'C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Lib\site-packages\osgeo\gdal204.dll'

libgdal.py
 # Windows NT shared libraries
    lib_names = ['gdal302','gdal301', 'gdal300', 'gdal204', 'gdal203', 'gdal202', 'gdal201', 'gdal20']

manage.py check now gives me

django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIBRARY_PATH in your settings.

Thank you very much for all your help again

Stathis

Vladimir Stupar

unread,
Mar 13, 2021, 7:34:30 AM3/13/21
to geod...@googlegroups.com
Hi Stathis,

Everyone new to python (or new to anything) has troubles in the beginning, so don't worry.

When it comes to paths and environments its quite common cause of getting stuck when starting with Python and I would recommend some of the great online tutorials to help you move on with this. My personal favorite is Corey Schafer, and I think you would benefit from at least these two basic videos about paths and environments:

After you've done this, you should have better understanding about paths and environments. If you don't, go check other Corey's video that cover more basic stuff, including python installation, working in the command line etc.  t helped a lot of people to get started.

Regarding your environmental variables, you still don't do exactly what I told you. It is essential to exactly replicate each step to be sure it will work. Otherwise, any little difference could mean that your code will not work as it should.

1.
~~~~~~~~~~~~~
Delete the following environmental variables:

GDAL_DRIVER_PATH: C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Lib
GDAL_LIBRARY_PATH: C:\OSGeo4W64\share\proj; C:\OSGeo4W64\share\gdal; C:\OSGeo4W64\bin\gdal204.dll;C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Lib\site-packages\django\contrib\gis\gdal;C:\Users\sangelrd\envs\mymap\lib\site-packages
GEOS_LIBRARY_PATH: C:\OSGeo4W64\bin\geos_c.dll
~~~~~~~~~~~~~~~~~~

2.
~~~~~~~~~~~~~~~~~~~~~~~~
Modify variable GDAL_DATA from:

GDAL_DATA: C:\OSGeo4W64\share\gdal;C:\Users\sangelrd\Envs\mymap\Lib\site-packages\osgeo;C:\Users\sangelrd\Envs\mymap\Lib\site-packages
to

GDAL_DATA: C:\OSGeo4W64\share\gdal
~~~~~~~~~~~~~~~~~~~~~~~~

3.
~~~~~~~~~~~~~~~~~~~~~~~~
Add variable PROJ_LIB as:
PROJ_LIB: C:\OSGeo4W64\share\proj
~~~~~~~~~~~~~~~~~~~~~~~

4.
~~~~~~~~~~~~~~~~~
The next thing that is really important is if you installed all of the packages you pip freezed into the virtual environment. From what you showed, i.e
Pip freeze
C:\Users\sangelrd\projects\mymap>pip freeze

you are just in the folder of your project, but you are showing packages from global environment.

If you were in virtual environment the command prompt would look like this:

(mymap) C:\Users\sangelrd\projects\mymap>pip freeze

Also, I see virtual environment packages which you would normally install globally and not inside your virtual env.

On the other hand maybe you were in the virtual environment, but just forgot to copy the "(mymap)" part. But knowing this is crucial and we need to get it straight, so if you did create virtual environment "mymap" you should activate it with "workon mymap" command (if you are using virtualenvwrapper ) and then pip freeze. If you dont's see the packages installed, then firstly you need to pip install them from inside "mymap" environment (not just the folder). Inside your virtual environment you would like to inastall packages you would use with your project only, so probably Django, GDAL and Rtree.
After you are done and clear with the installation of your virtual env, you should save the dependencies inside requirements.txt file for future use (you can easily find videos about this on youtube).
~~~~~~~~~~~~~~~

5.
~~~~~~~~~~~~~~~~~~~
The next thing is that your  variable GDAL_LIBRARY_PATH = r'C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Lib\site-packages\osgeo\gdal204.dll'  frpm your settings file is not good.
Here you need to point to "gdal.dll" file inside osgeo folder of your virtual environment. So it needs to look like this:
GDAL_LIBRARY_PATH = r' C:\Users\sangelrd\Envs\mymap\Lib\site-packages\osgeo\gdal204.dll'

If you can not find the folder 'C:\Users\sangelrd\Envs\mymap\Lib\site-packages\osgeo', that means you didn't install GDAL inside your virtual environment

but make sure that you add this just in the settings file, and not in your windows environmental variables.
~~~~~~~~~~~~~~~~~

6.
~~~~~~~~~~~~~~~~~
Also the location of "libgdal.py" file is in your virtual environment:
C:\Users\sangelrd\Envs\mymap\Lib\site-packages\django\contrib\gis\gdal\libgdal.py
so go there to add 'gdal204' in lib_names variable if it isn't already there.

If you can not find the folder 'C:\Users\sangelrd\Envs\mymap\Lib\site-packages\django' it means you didn't install Django inside your virtual environment.
~~~~~~~~~~~~~~~~~

When you do everything exactly as I told you, and there is still an error, post it immediately. It will make it easier for me to help you, if you don't start to make changes on your own trying to figure out the solution.

All the best,

Vlado




--
Vladimir Stupar

Stathis Angelou

unread,
Mar 17, 2021, 11:07:47 AM3/17/21
to geodjango
Good afternoon Vlado and thank you for your message.

First of all thank you very much for your time, effort and patience in helping me resolving this  issue, i am more than words grateful, please see my comments below



On Saturday, March 13, 2021 at 12:34:30 PM UTC Vlado wrote:
Hi Stathis,

Everyone new to python (or new to anything) has troubles in the beginning, so don't worry.

When it comes to paths and environments its quite common cause of getting stuck when starting with Python and I would recommend some of the great online tutorials to help you move on with this. My personal favorite is Corey Schafer, and I think you would benefit from at least these two basic videos about paths and environments:

Honestly really informative video, it really gave me a good understanding  of setting up the variables in windows
 
After you've done this, you should have better understanding about paths and environments. If you don't, go check other Corey's video that cover more basic stuff, including python installation, working in the command line etc.  t helped a lot of people to get started.

Regarding your environmental variables, you still don't do exactly what I told you. It is essential to exactly replicate each step to be sure it will work. Otherwise, any little difference could mean that your code will not work as it should.

1. Done
~~~~~~~~~~~~~
Delete the following environmental variables:

GDAL_DRIVER_PATH: C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Lib
GDAL_LIBRARY_PATH: C:\OSGeo4W64\share\proj; C:\OSGeo4W64\share\gdal; C:\OSGeo4W64\bin\gdal204.dll;C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Lib\site-packages\django\contrib\gis\gdal;C:\Users\sangelrd\envs\mymap\lib\site-packages
GEOS_LIBRARY_PATH: C:\OSGeo4W64\bin\geos_c.dll
~~~~~~~~~~~~~~~~~~

2. Done
~~~~~~~~~~~~~~~~~~~~~~~~
Modify variable GDAL_DATA from:

GDAL_DATA: C:\OSGeo4W64\share\gdal;C:\Users\sangelrd\Envs\mymap\Lib\site-packages\osgeo;C:\Users\sangelrd\Envs\mymap\Lib\site-packages
to

GDAL_DATA: C:\OSGeo4W64\share\gdal
~~~~~~~~~~~~~~~~~~~~~~~~

3. Done
~~~~~~~~~~~~~~~~~~~~~~~~
Add variable PROJ_LIB as:
PROJ_LIB: C:\OSGeo4W64\share\proj
~~~~~~~~~~~~~~~~~~~~~~~

4. 
~~~~~~~~~~~~~~~~~
The next thing that is really important is if you installed all of the packages you pip freezed into the virtual environment. From what you showed, i.e
Pip freeze
C:\Users\sangelrd\projects\mymap>pip freeze

you are just in the folder of your project, but you are showing packages from global environment.

If you were in virtual environment the command prompt would look like this:

(mymap) C:\Users\sangelrd\projects\mymap>pip freeze

(mymap) C:\Users\sangelrd\Envs\mymap>pip freeze
Django==3.1.7
GDAL @ file:///C:/Users/sangelrd/Envs/mymap/GDAL-2.4.1-cp36-cp36m-win_amd64.whl
Rtree==0.9.7

but in order to setup Spatialite which i need for my application i ended up with:

(mymap) C:\Users\sangelrd\Envs\mymap>pip freeze
asgiref==3.3.1
Django==3.1.7
GDAL @ file:///C:/Users/sangelrd/Envs/mymap/GDAL-2.4.1-cp36-cp36m-win_amd64.whl
psycopg2==2.8.6
pytz==2021.1
Rtree==0.9.7
spatialite==0.0.3
sqlparse==0.4.1

Also, I see virtual environment packages which you would normally install globally and not inside your virtual env.

On the other hand maybe you were in the virtual environment, but just forgot to copy the "(mymap)" part. But knowing this is crucial and we need to get it straight, so if you did create virtual environment "mymap" you should activate it with "workon mymap" command (if you are using virtualenvwrapper ) and then pip freeze. If you dont's see the packages installed, then firstly you need to pip install them from inside "mymap" environment (not just the folder). Inside your virtual environment you would like to inastall packages you would use with your project only, so probably Django, GDAL and Rtree.
After you are done and clear with the installation of your virtual env, you should save the dependencies inside requirements.txt file for future use (you can easily find videos about this on youtube).

I also did setup requirements
(mymap) C:\Users\sangelrd\Envs\mymap>pip freeze > requirements.txt 
~~~~~~~~~~~~~~~

5. Done
~~~~~~~~~~~~~~~~~~~
The next thing is that your  variable GDAL_LIBRARY_PATH = r'C:\Users\sangelrd\AppData\Local\Programs\Python\Python36\Lib\site-packages\osgeo\gdal204.dll'  frpm your settings file is not good.
Here you need to point to "gdal.dll" file inside osgeo folder of your virtual environment. So it needs to look like this:
GDAL_LIBRARY_PATH = r' C:\Users\sangelrd\Envs\mymap\Lib\site-packages\osgeo\gdal204.dll' - Added in the settings file

If you can not find the folder 'C:\Users\sangelrd\Envs\mymap\Lib\site-packages\osgeo', that means you didn't install GDAL inside your virtual environment - Folder is there

but make sure that you add this just in the settings file, and not in your windows environmental variables.
~~~~~~~~~~~~~~~~~

6. Already exists
lib_names = ['gdal302','gdal301', 'gdal300', 'gdal204', 'gdal203', 'gdal202', 'gdal201', 'gdal20'] 
~~~~~~~~~~~~~~~~~
Also the location of "libgdal.py" file is in your virtual environment:
C:\Users\sangelrd\Envs\mymap\Lib\site-packages\django\contrib\gis\gdal\libgdal.py
so go there to add 'gdal204' in lib_names variable if it isn't already there.

If you can not find the folder 'C:\Users\sangelrd\Envs\mymap\Lib\site-packages\django' it means you didn't install Django inside your virtual environment.
~~~~~~~~~~~~~~~~~

When you do everything exactly as I told you, and there is still an error, post it immediately. It will make it easier for me to help you, if you don't start to make changes on your own trying to figure out the solution.

All the best,

Vlado

- (mymap) C:\Users\sangelrd\Envs\mymap>python manage.py makemigrations

now gives me 
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\commands\makemigrations.py", line 101, in handle
    loader.check_consistent_history(connection)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\migrations\loader.py", line 290, in check_consistent_history
    applied = recorder.applied_migrations()
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\migrations\recorder.py", line 77, in applied_migrations
    if self.has_table():
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\migrations\recorder.py", line 55, in has_table
    with self.connection.cursor() as cursor:
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\utils\asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\backends\base\base.py", line 259, in cursor
    return self._cursor()
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\backends\base\base.py", line 235, in _cursor
    self.ensure_connection()
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\utils\asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
    self.connect()
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\utils\asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\contrib\gis\db\backends\spatialite\base.py", line 64, in get_new_connection
    'Library names tried: %s' % ', '.join(self.lib_spatialite_paths)
django.core.exceptions.ImproperlyConfigured: Unable to load the SpatiaLite library extension. Library names tried: mod_spatialite.so, mod_spatialite

tried to install pyspatialite via pip

- got error Is sphinx installed? If not, try 'sudo easy_install sphinx'."

so went  via pip install sphinx

(mymap) C:\Users\sangelrd\Envs\mymap>pip freeze
alabaster==0.7.12
asgiref==3.3.1
Babel==2.9.0
certifi==2020.12.5
chardet==4.0.0
colorama==0.4.4
Django==3.1.7
docutils==0.16
GDAL @ file:///C:/Users/sangelrd/Envs/mymap/GDAL-2.4.1-cp36-cp36m-win_amd64.whl
idna==2.10
imagesize==1.2.0
Jinja2==2.11.3
MarkupSafe==1.1.1
packaging==20.9
psycopg2==2.8.6
Pygments==2.8.1
pyparsing==2.4.7
pytz==2021.1
requests==2.25.1
Rtree==0.9.7
snowballstemmer==2.1.0
spatialite==0.0.3
Sphinx==3.5.2
sphinxcontrib-applehelp==1.0.2
sphinxcontrib-devhelp==1.0.2
sphinxcontrib-htmlhelp==1.0.3
sphinxcontrib-jsmath==1.0.1
sphinxcontrib-qthelp==1.0.3
sphinxcontrib-serializinghtml==1.1.4
sqlparse==0.4.1
urllib3==1.26.4

so now again

(mymap) C:\Users\sangelrd\Envs\mymap>python manage.py makemigrations
Traceback (most recent call last):
  File "manage.py", line 22, in <module>
    main()
  File "manage.py", line 18, in main
    execute_from_command_line(sys.argv)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\__init__.py", line 401, in execute_from_command_line
    utility.execute()
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\__init__.py", line 395, in execute
    self.fetch_command(subcommand).run_from_argv(self.argv)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\base.py", line 330, in run_from_argv
    self.execute(*args, **cmd_options)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\base.py", line 371, in execute
    output = self.handle(*args, **options)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\base.py", line 85, in wrapped
    res = handle_func(*args, **kwargs)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\core\management\commands\makemigrations.py", line 101, in handle
    loader.check_consistent_history(connection)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\migrations\loader.py", line 290, in check_consistent_history
    applied = recorder.applied_migrations()
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\migrations\recorder.py", line 77, in applied_migrations
    if self.has_table():
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\migrations\recorder.py", line 55, in has_table
    with self.connection.cursor() as cursor:
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\utils\asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\backends\base\base.py", line 259, in cursor
    return self._cursor()
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\backends\base\base.py", line 235, in _cursor
    self.ensure_connection()
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\utils\asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\backends\base\base.py", line 219, in ensure_connection
    self.connect()
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\utils\asyncio.py", line 26, in inner
    return func(*args, **kwargs)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\db\backends\base\base.py", line 200, in connect
    self.connection = self.get_new_connection(conn_params)
  File "C:\Users\sangelrd\Envs\mymap\lib\site-packages\django\contrib\gis\db\backends\spatialite\base.py", line 64, in get_new_connection
    'Library names tried: %s' % ', '.join(self.lib_spatialite_paths)
django.core.exceptions.ImproperlyConfigured: Unable to load the SpatiaLite library extension. Library names tried: mod_spatialite.so, mod_spatialite

gives me the same error

Do i possibly need to install spatialite via:

Thank you very much again for all your help

Stathis

Vladimir Stupar

unread,
Mar 17, 2021, 11:17:52 AM3/17/21
to geod...@googlegroups.com
Hi Stathis,

Why would you need spatialite if you are using Postgis?

--
You received this message because you are subscribed to the Google Groups "geodjango" group.
To unsubscribe from this group and stop receiving emails from it, send an email to geodjango+...@googlegroups.com.

ma...@data-halo.com

unread,
Mar 17, 2021, 11:47:15 AM3/17/21
to geodjango
So, it is a number of years later and I see there is still discussion about Windows installation. What I am about to say could be viewed as supremely unhelpful, but in another sense it could save your projects. 

After using Windows Server in production for 6 years with my Software-as-a-Service, I now use Ubuntu. The reason I went with Windows so long is that all my career I was a civil/survey CAD technician and in that industry Windows is the only OS we knew, and Linux seemed intimidating from the outside. My introduction to programming, and later Python/Django was all in the Windows environment and I found the Bitnami Django Stack which took care of many dependencies so I could just code my application. Still, it was a huge issue at times to make sure GDAL and Apache server played nicely together. Also, much of the documentation about best practices assumed you were in a Linux environment, so I was often trying to find work-arounds. All this resulted in a struggle to keep my stack up-to-date while worrying something would break if I barely touched it.

Last summer, for fun, I bought a Raspberry Pi. I discovered that Linux was not intimidating at all. I discovered I was able to install my stack on the Pi with its native OS, and serve up my SaaS to my home network. Then I installed Ubuntu to the Pi and my SaaS stack installation was even easier. I went and bought a Dell Ubuntu laptop and immersed myself in the Linux environment and now at my data center all my VM's that run my SaaS are Ubuntu. Life is very good in that environment, updates are easy, every add-on works, all the Django advice I find online applies to my situation.

So, on the one hand my comments about Linux are very unhelpful to people who simply can't switch environments. But I would encourage you that learning enough basic Linux is far easier than learning how to maintain Django on Windows.

Stathis Angelou

unread,
May 4, 2021, 6:40:41 AM5/4/21
to geodjango

Good morning Vlado and everyone in this discussion, apologies for my hiatus period, massive workload/end of financial year overtook all of my time,

Also after reading Vlado's last post made me revisit my methodology, cause the one i had in hand did use spatialite spatial extension.

Also i am waiting for a linux environment to be built (working for a organisation does increase the relevant times to have things built).

as it is a windows environment we firstly went for the Windows Linux subsystem, but because of the Windows version it didn't work as expected, so i am now waiting for a new linux server to be built so as to built the required environment and repositories.

I will keep you posted for any further developments

Thank you very much again

Stathis
Reply all
Reply to author
Forward
0 new messages