问题描述
我一直在尝试设置Windows计算机,以便可以使用具有PostGIS扩展名的本地postgreSQL.安装此程序后,我希望能够在本地将geodjango创建项目后再将其放入云中.我已经在使用SQLite DB的本地计算机上与Django一起工作了一段时间,但是由于下一个项目将部分基于基于坐标的数据,所以我想设置正确的环境.
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.
导入说明:我已经安装了mini-conda以便在单独的环境中运行.我在工作时确实会激活此环境开发"
我已尝试在线跟踪大多数geodjango信息/教程,但无法使其正常工作.我所做的(大多数情况是: https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/#windows ):
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):
- 从 https://www.enterprisedb下载并安装最新(10.3)PostgreSQL设置.com/downloads/postgres-postgresql-downloads
- 安装后,我还使用Application Stack Builder安装了PostGis
- 我已经从 https://trac.osgeo.org/osgeo4w/
- 我已经按照geodjango网站( https://docs.djangoproject.com/en/2.0/ref/contrib/gis/install/#windows )并以管理员身份运行(除了将路径设置为python的部分,因为我已经使用python一段时间了,所以python已经在里面了
- 我在psql shell中尝试了一些命令,我想我已经创建了一个数据库,名称为:geodjango,用户名:****并通过:****.
- 我不知道是否已给geodjango用户所有特权,但我怀疑是这样.
- Download and install the latest (10.3) PostgreSQL setup from https://www.enterprisedb.com/downloads/postgres-postgresql-downloads
- After installation I also installed used the Application Stack Builder to install PostGis
- I've installed OSGeo4W from https://trac.osgeo.org/osgeo4w/
- 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)
- I've tried some command in psql shell and I think I've created a database with name: geodjango, username: **** and pass: ****.
- I don't know if I have given the geodjango user all priveleges, but I suspect so.
所有这些之后,我创建了一个新的django项目,并在settings.py中添加了一些部分:
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',
]
我也在settings.py中得到了这个
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)
当我尝试在Django中设置数据库时,我会运行(在正确的文件夹中):
When I try to set up the database in django I run (in the right folder):
python manage.py makemigrations
我收到以下错误:
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?
更新7-3-2018:
Update 7-3-2018:
- 我尝试自己亲自安装GDAL,(来自: http://www.gisinternals.com/query.html?content=filelist&file=release-1911-x64-gdal-2- 2-3-mapserver-7-0-7.zip 通用核心组件)
- 我已经安装(假设是)来自 https://的python绑定www.lfd.uci.edu/~gohlke/pythonlibs/.仍然我得到同样的错误.
- 我还尝试将GDAL_LIBRARY_PATH设置为GDAL目录或gdal-data目录(位于GDAL目录中).
- I've tried installing GDAL manually myself, (from: http://www.gisinternals.com/query.html?content=filelist&file=release-1911-x64-gdal-2-2-3-mapserver-7-0-7.zip the generic core components)
- I've installed (what I assume are) the python bindings from https://www.lfd.uci.edu/~gohlke/pythonlibs/. Still I get the same error.
- I've also tried setting the GDAL_LIBRARY_PATH to the GDAL directory or the gdal-data directory (which resides in the GDAL directory).
现在出现以下错误:
OSError: [WinError 126] The specified module could not be found
(.dll在那里...)
(while the .dll is there...)
推荐答案
我发现以下内容适用于Windows:
I have found the following to work for windows:
- 运行
python
来检查您的 python 是32位还是64位. - 将相应的 OSGeo4W (32或64位)安装到
C:\OSGeo4W
或C:\OSGeo4W64
中:- 注意::选择"Express Web-GIS安装",然后单击下一步".
- 在选择软件包"列表中,确保已选择GDAL;默认情况下,MapServer和Apache也处于启用状态,可能会被安全地取消选中.
- Run
python
to check if your python is 32 or 64 bit. - Install corresponding OSGeo4W (32 or 64 bit) into
C:\OSGeo4W
orC:\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.
确保以下内容包含在您的
settings.py
中: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"\share\gdal" os.environ['PROJ_LIB'] = OSGEO4W + r"\share\proj" os.environ['PATH'] = OSGEO4W + r"\bin;" + os.environ['PATH']
-
运行
python manage.py check
以验证geodjango是否正常工作. Run
python manage.py check
to verify geodjango is working correctly.这篇关于Windows上的GeoDjango:“找不到GDAL库"; /"OSError:[WinError 126]找不到指定的模块".的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持!