I followed with instruction: https://docs.djangoproject.com/en/4.0/ref/contrib/gis/install/ for Windows 10 I downloaded Postgres and added installed Postgis. Then OSGeo4W in the folder C:\OSGeo4W and maked point Modify Windows environment
I create new project and one application.
In settings.py added:
DATABASES = {
'default': {
'ENGINE': 'django.contrib.gis.db.backends.postgis',
'NAME': 'geodjango',
'USER': 'geo',
},
}
After run py manage.py runserver I get a error: django.core.exceptions.ImproperlyConfigured: Could not find the GDAL library (tried "gdal303", "gdal302", "gdal301", "gdal300", "gdal204", "gdal203", "gdal202", "gdal201", "gdal20"). Is GDAL installed? If it is, try setting GDAL_LIB RARY_PATH in your settings.
I add (Python Root)\Lib\site-packages\django\contrib\gis\gdal\libgdal.py "gdal305" , becauuse this file i have in C:\OSGeo4W\bin. I get a error: FileNotFoundError: Could not find module 'C:\OSGeo4W\bin\gdal305.dll' (or one of its dependencies). Try using the full path with constructor syntax. (this path is good ) In settings.py I add: GDAL_LIBRARY_PATH = r'C:\OSGeo4W\bin\gdal505', but I'm showing the same error as before. So I try 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']
And I still get the same error: FileNotFoundError: Could not find module 'C:\OSGeo4W\bin\gdal305.dll' (or one of its dependencies). Try using the full path with constructor syntax.
The Python version 3.9.2 64bit In the moment when I want to check a version OSGeo4W i get information, that don't find a file. enter image description here
Please about more tips.
Check whether you have gdal305.dll in your OSGEO4W/bin folder. If it is there, then check whether you included gdal305 in your libgdal.py file.
elif os.name == "nt":
# Windows NT shared libraries
lib_names = [
"gdal305",
"gdal304",
"gdal303",
"gdal302",
"gdal301",
"gdal300",
"gdal204",
"gdal203",
"gdal202",
"gdal201",
"gdal20",
]
Then restart your application and check whether it is working.
The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.