问题描述
我尝试将 Django
与 Geodjango
结合使用,我遵循了所有文档步骤,但是在尝试进行迁移时仍然遇到此错误:
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
models.py
是正确的,我在 geodjango
网站上使用,这是我的 settings.py
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/'
这是我得到的错误:
>>> 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
我已检查并安装了 geodjango
的所有要求.
I checked and all requeriments for geodjango
are installed.
有什么建议吗?
推荐答案
您可能有多个Python版本,并且它们之间存在冲突.
You probably have multiple Python versions and there is conflict between them.
尝试在您的virtualenv上安装GDAL,并确保gdal202.dll在您的virtualenv上下文中.
Try to install the GDAL on your virtualenv and ensure that the gdal202.dll is in your virtualenv context.
还要确保您从 https://www安装了正确的编译版本.lfd.uci.edu/〜gohlke/pythonlibs/#gdal ,使用pip在您的virtualenv内部.
Also ensure that you installed the right compiled version from https://www.lfd.uci.edu/~gohlke/pythonlibs/#gdal, using pip and inside your virtualenv.
GDAL DLL将位于gdal安装路径中.我在settings.py中使用如下代码在Windows上设置GeoDjango:
The GDAL DLL will be in the gdal installation path. I use a code like this in settings.py to setup GeoDjango on Windows:
try:
import gdal
gdal_path = Path(gdal.__file__)
OSGEO4W = os.path.join(gdal_path.parent, 'osgeo')
os.environ["OSGEO4W_ROOT"] = OSGEO4W
os.environ["GDAL_DATA"] = os.path.join(OSGEO4W, "data", "gdal")
os.environ["PROJ_LIB"] = os.path.join(OSGEO4W, "data", "proj")
os.environ["PATH"] = OSGEO4W + ";" + os.environ["PATH"]
GEOS_LIBRARY_PATH = str(os.path.join(OSGEO4W, "geos_c.dll"))
GDAL_LIBRARY_PATH = str(os.path.join(OSGEO4W, "gdal301.dll"))
except ImportError:
GEOS_LIBRARY_PATH = None
GDAL_LIBRARY_PATH = None
这篇关于Geodjango中的OSError:[WinError 127]:找不到指定的过程的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!