OSError in Geodjango: [WinError 127] : The specified procedure could not be found

妖精的绣舞 提交于 2019-12-24 05:47:55

问题


Im trying to use Django with Geodjango, I followed all documentation steps, but still got this error when trying to make migrations:

OSError: [WinError 127] : The specified procedure could not be found

The models.py is correct, I'm using from geodjango site, and this is my settings.py

import os

# Build paths inside the project like this: os.path.join(BASE_DIR, ...)
BASE_DIR = os.path.dirname(os.path.dirname(os.path.abspath(__file__)))


# Quick-start development settings - unsuitable for production
# See https://docs.djangoproject.com/en/2.1/howto/deployment/checklist/

# SECURITY WARNING: keep the secret key used in production secret!
SECRET_KEY = 'ci3qd6ti+d+#-4pae7d*)^8nmmgb2j@cacivgt8rdvsngu2$mj'

# SECURITY WARNING: don't run with debug turned on in production!
DEBUG = True

ALLOWED_HOSTS = []


# Application definition

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

MIDDLEWARE = [
    'django.middleware.security.SecurityMiddleware',
    'django.contrib.sessions.middleware.SessionMiddleware',
    'django.middleware.common.CommonMiddleware',
    'django.middleware.csrf.CsrfViewMiddleware',
    'django.contrib.auth.middleware.AuthenticationMiddleware',
    'django.contrib.messages.middleware.MessageMiddleware',
    'django.middleware.clickjacking.XFrameOptionsMiddleware',
]

ROOT_URLCONF = 'geodjango.urls'

TEMPLATES = [
    {
        'BACKEND': 'django.template.backends.django.DjangoTemplates',
        'DIRS': [],
        'APP_DIRS': True,
        'OPTIONS': {
            'context_processors': [
                'django.template.context_processors.debug',
                'django.template.context_processors.request',
                'django.contrib.auth.context_processors.auth',
                'django.contrib.messages.context_processors.messages',
            ],
        },
    },
]

WSGI_APPLICATION = 'geodjango.wsgi.application'


# Database
# https://docs.djangoproject.com/en/2.1/ref/settings/#databases

DATABASES = {
    'default': {
    'ENGINE': 'django.db.backends.postgresql',
    'NAME': 'test',
    'USER': 'postgres',
    'PASSWORD': '*********',
    'HOST': '127.0.0.1',
    'PORT': '5432',
    }

}


# Password validation
# https://docs.djangoproject.com/en/2.1/ref/settings/#auth-password-validators

AUTH_PASSWORD_VALIDATORS = [
    {
        'NAME': 'django.contrib.auth.password_validation.UserAttributeSimilarityValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.MinimumLengthValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.CommonPasswordValidator',
    },
    {
        'NAME': 'django.contrib.auth.password_validation.NumericPasswordValidator',
    },
]


# Internationalization
# https://docs.djangoproject.com/en/2.1/topics/i18n/

LANGUAGE_CODE = 'en-us'

TIME_ZONE = 'UTC'

USE_I18N = True

USE_L10N = True

USE_TZ = True


# Static files (CSS, JavaScript, Images)
# https://docs.djangoproject.com/en/2.1/howto/static-files/

STATIC_URL = '/static/'

And this is the error I get:

>>> python manage.py makemigrations

Traceback (most recent call last):
  File "manage.py", line 15, in <module>
    execute_from_command_line(sys.argv)
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\core\management\__init__.py", line 381, in execute_from_command_line
    utility.execute()
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\core\management\__init__.py", line 357, in execute
    django.setup()
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\__init__.py", line 24, in setup
    apps.populate(settings.INSTALLED_APPS)
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\apps\registry.py", line 112, in populate
    app_config.import_models()
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\apps\config.py", line 198, in import_models
    self.models_module = import_module(models_module_name)
  File "C:\Users\hades\AppData\Local\Programs\Python\Python37\Lib\importlib\__init__.py", line 127, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
  File "<frozen importlib._bootstrap>", line 983, in _find_and_load
  File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
  File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
  File "<frozen importlib._bootstrap_external>", line 728, in exec_module
  File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
  File "C:\Users\hades\PycharmProjects\meumapa\geodjango\world\models.py", line 3, in <module>
    from django.contrib.gis.db import models
  File "C:\Users\hades\PycharmProjects\geodjango\venv\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\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\contrib\gis\db\models\functions.py", line 4, in <module>
    from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\contrib\gis\db\models\fields.py", line 3, in <module>
    from django.contrib.gis import forms, gdal
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\contrib\gis\forms\__init__.py", line 3, in <module>
    from .fields import (  # NOQA
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\contrib\gis\forms\fields.py", line 2, in <module>
    from django.contrib.gis.geos import GEOSException, GEOSGeometry
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\contrib\gis\geos\__init__.py", line 5, in <module>
    from .collections import (  # NOQA
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\contrib\gis\geos\collections.py", line 9, in <module>
    from django.contrib.gis.geos.geometry import GEOSGeometry, LinearGeometryMixin
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\contrib\gis\geos\geometry.py", line 8, in <module>
    from django.contrib.gis import gdal
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\contrib\gis\gdal\__init__.py", line 28, in <module>
    from django.contrib.gis.gdal.datasource import DataSource
  File "C:\Users\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\contrib\gis\gdal\datasource.py", line 39, in <module>
    from django.contrib.gis.gdal.driver import Driver
  File "C:\Users\hades\PycharmProjects\geodjango\venv\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\hades\PycharmProjects\geodjango\venv\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\hades\PycharmProjects\geodjango\venv\lib\site-packages\django\contrib\gis\gdal\libgdal.py", line 47, in <module>
    lgdal = CDLL(lib_path)
  File "C:\Users\hades\AppData\Local\Programs\Python\Python37\Lib\ctypes\__init__.py", line 356, in __init__
    self._handle = _dlopen(self._name, mode)
OSError: [WinError 127] The specified procedure could not be found

I checked and all requeriments for geodjango are installed.

Any suggestions?


回答1:


You probably have multiple Python versions and there is conflict between them.

Try to install the GDAL on your virtualenv and ensure that the gdal202.dll is in your virtualenv context.

Also ensure that you installed the right compiled version from https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal, using pip and inside your virtualenv.



来源:https://stackoverflow.com/questions/51833501/oserror-in-geodjango-winerror-127-the-specified-procedure-could-not-be-foun

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!