Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
636 views
in Technique[技术] by (71.8m points)

python - GeoDjango on Windows: "Could not find the GDAL library" / "OSError: [WinError 126] The specified module could not be found"

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 geodjango locally before putting it in the cloud. I have been working with Django for a little while now on my local machine with the SQLite DB, but since the next project will partly be based on coordinate based data I wanted to setup the right environment.

Import note: I've installed mini-conda to run in a seperate environment. I do activate this environment "development" when I work though

I've tried to follow most of the geodjango information/tutorials online, but can't get it to work. What I've done (mostly followed this: https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/#windows):

  1. Download and install the latest (10.3) PostgreSQL setup from https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
  2. After installation I also installed used the Application Stack Builder to install PostGis
  3. I've installed OSGeo4W from https://trac.osgeo.org/osgeo4w/
  4. I've created a batch script as described on the geodjango website (https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/#windows) and ran it as administrator (except for the part where it sets the path to python, cause python was already in there since I've been using python for a while now)
  5. I've tried some command in psql shell and I think I've created a database with name: geodjango, username: **** and pass: ****.
  6. I don't know if I have given the geodjango user all priveleges, but I suspect so.

After all of this I created a new django project and in settings.py I've added some parts:

INSTALLED_APPS = [
'django.contrib.admin',
'django.contrib.auth',
'django.contrib.contenttypes',
'django.contrib.sessions',
'django.contrib.messages',
'django.contrib.staticfiles',
'django.contrib.gis',
'nameOfMyApp',
]

I've also got this in settings.py:

DATABASES = {
'default': {
    'ENGINE': 'django.contrib.gis.db.backends.postgis',
    'NAME': 'geodjango',
    'USER': '****',
    'PASSWORD': '****',
    'HOST': 'localhost',
}
}

# FOR GEODJANGO
POSTGIS_VERSION = (2, 4, 3)

When I try to set up the database in django I run (in the right folder):

python manage.py makemigrations

I get the following error:

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

I've tried to fix that, but nothing seems to work. Can anybody give me some help in setting this all up locally?

Update 7-3-2018:

Now I get the following error:

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

(while the .dll is there...)

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I have found the following to work for windows:

  • Run python to check if your python is 32 or 64 bit.
  • Install corresponding OSGeo4W (32 or 64 bit) into C:OSGeo4W or C:OSGeo4W64:
    • Note: Select Express Web-GIS Install and click next.
    • In the ‘Select Packages’ list, ensure that GDAL is selected; MapServer and Apache are also enabled by default, may be unchecked safely.
  • Make sure the following is included in your 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"sharegdal"
        os.environ['PROJ_LIB'] = OSGEO4W + r"shareproj"
        os.environ['PATH'] = OSGEO4W + r"in;" + os.environ['PATH']
    
  • Run python manage.py check to verify geodjango is working correctly.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...