“模块”对象没有属性“OSMGeoAdmin”;
环境如下:
**Windows 7**
PATH=C:\Python27\;C:\Python27\Scripts;C:\Python27\Lib\site-packages\MySQLdb;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\OSGeo4W\bin
**python 2.7**
'C:\\Python27\\lib\\site-packages\\bitstring-2.1.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\virtualenvwrapper-2.11.1-py2.7.egg', 'c:\\cygwin\\home\\username\\__prjs\\flt\\requirements\\src\\djangoembed', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info'
我找到的几个问题让我检查了我的 GDAL 安装和路径,但它是正确的,如下所示:
set OSGEO4W_ROOT=C:\OSGeo4W
set GEOS_LIBRARY_PATH=%OSGEO4W_ROOT%\bin
set GDAL_DATA=%OSGEO4W_ROOT%\share\gdal
哦!另一件事是,当我在 python 中并尝试调用 admin.py 时,
>>> import django.contrib.gis
>>> import admin
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named admin
我正在为非营利项目工作,很少有帮助者,但还有很多工作要做,所以请围绕这方面的任何想法将非常感激。
根据 Rob Wouters 的回答,我收到了根本原因错误。
>>> import django.contrib.gis.admin
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\django\contrib\gis\admin\__init__.py", line 2, in <module>
from django.contrib.admin import autodiscover, site, AdminSite, ModelAdmin, StackedInline, TabularInline, HORIZONTAL, VERTICAL
File "C:\Python27\lib\site-packages\django\contrib\admin\__init__.py", line 3, in <module>
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "C:\Python27\lib\site-packages\django\contrib\admin\helpers.py", line 3, in <module>
from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
File "C:\Python27\lib\site-packages\django\contrib\admin\util.py", line 1, in <module>
from django.db import models
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 14, in <module>
if not settings.DATABASES:
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 276, in __getattr__
self._setup()
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
我将阅读有关 Django_settings 的任何内容,我将发布它的工作原理。
虚拟环境路径如下:
(ve) C:\cygwin\home\holanda\__prjs\ourfield>env
!::=::\
!C:=C:\cygwin\home\holanda\__prjs\ourfield
.
.
.
DJANGO_SETTINGS_MODULE=ourfield.settings
.
.
.
GDAL_DATA=C:\OSGeo4W\share\gdal
GEOS_LIBRARY_PATH=C:\OSGeo4W\bin
GEOTIFF_CSV=C:\OSGeo4W\share\epsg_csv
.
.
.
HOME=/cygdrive/c/Users/holanda
HOMEDRIVE=C:
HOMEPATH=\Users\holanda
JAVA_HOME=C:\OSGeo4W\
.
.
.
OSGEO4W_ROOT=C:\OSGeo4W
PATH=/home/holanda/__prjs/ourfield/ve/Scripts:/cygdrive/c/Python27:/cygdrive/c/Python27/Scripts:/usr/bin:/cygdrive/c/Program Files/Common Files/Microsoft Shared/Windows Live:/cygdrive/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live:/cygdrive/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files (x86)/Common Files/Acronis/SnapAPI:/cygdrive/c/_tech/_mysql/bin:/cygdrive/c/masters/Console2/bin/release:/cygdrive/c/Program Files/Java/jdk1.7.0/bin/bin:/cygdrive/c/Program Files (x86)/Microsoft SQL Server/100/Tools/Binn:/cygdrive/c/Program Files (x86)/Microsoft SQL Server/100/DTS/Binn:/cygdrive/c/_tech/utils:/cygdrive/c/MinGW/bin:/cygdrive/c/Program Files (x86)/QuickTime/QTSystem:/cygdrive/c/Program Files (x86)/Windows Live/Shared:/cygdrive/c/Program Files (x86)/QuickTime/QTSystem:/cygdrive/c/Program Files/Git/cmd:/cygdrive/c/Python27/Lib/site-packages/MySQLdb:/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/bin:/cygdrive/c/OSGeo4W/bin:/cygdrive/c/Users/holanda/AppData/Roaming/Python/Scripts:/cygdrive/c/OSGeo4W/bin:/cygdrive/c/OSGeo4W/apps/msys/bin
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.py;.pyw
.
.
.
PROJECTS_ROOT=C:\cygwin\home\holanda\__prjs
PROJECT_NAME=ourfield
PROJECT_ROOT=C:\cygwin\home\holanda\__prjs\ourfield
PROJ_LIB=C:\OSGeo4W\share\proj
PROMPT=(ve) $P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
PYTHONPATH=C:\cygwin\home\holanda\__prjs;C:\cygwin\home\holanda\__prjs\ourfield;C:\cygwin\home\holanda\__prjs\ourfield\parts;C:\cygwin\home\holanda\__prjs\ourfield\apps;C:\cygwin\home\holanda\__prjs\ourfield\ve\Lib;C:\cygwin\home\holanda\__prjs\ourfield\ve\Lib\site-packages;C:\Python27;C:\Python27\Lib;C:\Python27\Lib\site-packages;C:\OSGeo4W\bin
PYTHONSTARTUP=~/.pythonrc
PYTHON_ROOT=C:\Python27
QTJAVA=C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip
QT_PLUGIN_PATH=C:\OSGeo4W\apps\Qt4\plugins
QT_RASTER_CLIP_LIMIT=4096
.
.
.
VBOX_INSTALL_PATH=C:\Program Files\Oracle\VirtualBox\
VIRTUAL_ENV=C:\cygwin\home\holanda\__prjs\ourfield\ve
VS90COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\
WINDIR=C:\Windows
.
.
.
TERM=cygwin
The enviroment is as follows:
**Windows 7**
PATH=C:\Python27\;C:\Python27\Scripts;C:\Python27\Lib\site-packages\MySQLdb;C:\Program Files\MySQL\MySQL Server 5.5\bin;C:\OSGeo4W\bin
**python 2.7**
'C:\\Python27\\lib\\site-packages\\bitstring-2.1.1-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg', 'C:\\Python27\\lib\\site-packages\\virtualenvwrapper-2.11.1-py2.7.egg', 'c:\\cygwin\\home\\username\\__prjs\\flt\\requirements\\src\\djangoembed', 'C:\\Windows\\system32\\python27.zip', 'C:\\Python27\\DLLs', 'C:\\Python27\\lib', 'C:\\Python27\\lib\\plat-win', 'C:\\Python27\\lib\\lib-tk', 'C:\\Python27', 'C:\\Python27\\lib\\site-packages', 'C:\\Python27\\lib\\site-packages\\PIL', 'C:\\Python27\\lib\\site-packages\\win32', 'C:\\Python27\\lib\\site-packages\\win32\\lib', 'C:\\Python27\\lib\\site-packages\\Pythonwin', 'C:\\Python27\\lib\\site-packages\\setuptools-0.6c11-py2.7.egg-info'
The few aswers I was able to found sent me to review my GDAL installation and path but it's correct as follows:
set OSGEO4W_ROOT=C:\OSGeo4W
set GEOS_LIBRARY_PATH=%OSGEO4W_ROOT%\bin
set GDAL_DATA=%OSGEO4W_ROOT%\share\gdal
OH! something else is when I am in python and try to call admin.py
>>> import django.contrib.gis
>>> import admin
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named admin
I am working for non-profit project and few are the helpers but much work to be done, so please any idea around this would be very appreaciated.
Based on Rob Wouters' answer I received the root cause error..
>>> import django.contrib.gis.admin
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "C:\Python27\lib\site-packages\django\contrib\gis\admin\__init__.py", line 2, in <module>
from django.contrib.admin import autodiscover, site, AdminSite, ModelAdmin, StackedInline, TabularInline, HORIZONTAL, VERTICAL
File "C:\Python27\lib\site-packages\django\contrib\admin\__init__.py", line 3, in <module>
from django.contrib.admin.helpers import ACTION_CHECKBOX_NAME
File "C:\Python27\lib\site-packages\django\contrib\admin\helpers.py", line 3, in <module>
from django.contrib.admin.util import (flatten_fieldsets, lookup_field,
File "C:\Python27\lib\site-packages\django\contrib\admin\util.py", line 1, in <module>
from django.db import models
File "C:\Python27\lib\site-packages\django\db\__init__.py", line 14, in <module>
if not settings.DATABASES:
File "C:\Python27\lib\site-packages\django\utils\functional.py", line 276, in __getattr__
self._setup()
File "C:\Python27\lib\site-packages\django\conf\__init__.py", line 40, in _setup
raise ImportError("Settings cannot be imported, because environment variable %s is undefined." % ENVIRONMENT_VARIABLE)
ImportError: Settings cannot be imported, because environment variable DJANGO_SETTINGS_MODULE is undefined.
I will be reading about Django_settings anything I will post what it worked.
The Virtual Enviroment path is as follows:
(ve) C:\cygwin\home\holanda\__prjs\ourfield>env
!::=::\
!C:=C:\cygwin\home\holanda\__prjs\ourfield
.
.
.
DJANGO_SETTINGS_MODULE=ourfield.settings
.
.
.
GDAL_DATA=C:\OSGeo4W\share\gdal
GEOS_LIBRARY_PATH=C:\OSGeo4W\bin
GEOTIFF_CSV=C:\OSGeo4W\share\epsg_csv
.
.
.
HOME=/cygdrive/c/Users/holanda
HOMEDRIVE=C:
HOMEPATH=\Users\holanda
JAVA_HOME=C:\OSGeo4W\
.
.
.
OSGEO4W_ROOT=C:\OSGeo4W
PATH=/home/holanda/__prjs/ourfield/ve/Scripts:/cygdrive/c/Python27:/cygdrive/c/Python27/Scripts:/usr/bin:/cygdrive/c/Program Files/Common Files/Microsoft Shared/Windows Live:/cygdrive/c/Program Files (x86)/Common Files/Microsoft Shared/Windows Live:/cygdrive/c/Program Files (x86)/NVIDIA Corporation/PhysX/Common:/cygdrive/c/Windows/system32:/cygdrive/c/Windows:/cygdrive/c/Windows/System32/Wbem:/cygdrive/c/Windows/System32/WindowsPowerShell/v1.0:/cygdrive/c/Program Files (x86)/Common Files/Acronis/SnapAPI:/cygdrive/c/_tech/_mysql/bin:/cygdrive/c/masters/Console2/bin/release:/cygdrive/c/Program Files/Java/jdk1.7.0/bin/bin:/cygdrive/c/Program Files (x86)/Microsoft SQL Server/100/Tools/Binn:/cygdrive/c/Program Files (x86)/Microsoft SQL Server/100/DTS/Binn:/cygdrive/c/_tech/utils:/cygdrive/c/MinGW/bin:/cygdrive/c/Program Files (x86)/QuickTime/QTSystem:/cygdrive/c/Program Files (x86)/Windows Live/Shared:/cygdrive/c/Program Files (x86)/QuickTime/QTSystem:/cygdrive/c/Program Files/Git/cmd:/cygdrive/c/Python27/Lib/site-packages/MySQLdb:/cygdrive/c/Program Files/MySQL/MySQL Server 5.5/bin:/cygdrive/c/OSGeo4W/bin:/cygdrive/c/Users/holanda/AppData/Roaming/Python/Scripts:/cygdrive/c/OSGeo4W/bin:/cygdrive/c/OSGeo4W/apps/msys/bin
PATHEXT=.COM;.EXE;.BAT;.CMD;.VBS;.VBE;.JS;.JSE;.WSF;.WSH;.MSC;.py;.pyw
.
.
.
PROJECTS_ROOT=C:\cygwin\home\holanda\__prjs
PROJECT_NAME=ourfield
PROJECT_ROOT=C:\cygwin\home\holanda\__prjs\ourfield
PROJ_LIB=C:\OSGeo4W\share\proj
PROMPT=(ve) $P$G
PSModulePath=C:\Windows\system32\WindowsPowerShell\v1.0\Modules\
PUBLIC=C:\Users\Public
PYTHONPATH=C:\cygwin\home\holanda\__prjs;C:\cygwin\home\holanda\__prjs\ourfield;C:\cygwin\home\holanda\__prjs\ourfield\parts;C:\cygwin\home\holanda\__prjs\ourfield\apps;C:\cygwin\home\holanda\__prjs\ourfield\ve\Lib;C:\cygwin\home\holanda\__prjs\ourfield\ve\Lib\site-packages;C:\Python27;C:\Python27\Lib;C:\Python27\Lib\site-packages;C:\OSGeo4W\bin
PYTHONSTARTUP=~/.pythonrc
PYTHON_ROOT=C:\Python27
QTJAVA=C:\Program Files (x86)\Java\jre6\lib\ext\QTJava.zip
QT_PLUGIN_PATH=C:\OSGeo4W\apps\Qt4\plugins
QT_RASTER_CLIP_LIMIT=4096
.
.
.
VBOX_INSTALL_PATH=C:\Program Files\Oracle\VirtualBox\
VIRTUAL_ENV=C:\cygwin\home\holanda\__prjs\ourfield\ve
VS90COMNTOOLS=C:\Program Files (x86)\Microsoft Visual Studio 9.0\Common7\Tools\
WINDIR=C:\Windows
.
.
.
TERM=cygwin
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(3)
您需要
导入 django.contrib.gis.admin
,而不仅仅是admin
。You need to
import django.contrib.gis.admin
, not justadmin
.我迟到了 4 年,但在升级到 osx El Captain 和 Homebrew 后我收到了这个错误。我在此处
OSMGeoAdmin 依赖于 gdal,因此我必须在升级后通过运行
brew install gdal
重新安装它。希望这可以帮助其他人在未来
I am 4 years late but I got this error after upgrading to osx El capitan and Homebrew. I found the solution here
OSMGeoAdmin
relies on gdal so I had to reinstall it after upgrading by runningbrew install gdal
.hope this might help someone else in the future
您需要从项目目录运行
python manage.py shell
,这会在您的 shell 中加载各种 django 特定变量,并防止出现ImportError
。编辑:
从批处理文件运行它和从外壳运行它不是一回事,这就是您收到这些错误的原因。
解决问题最简单的方法是创建一个自定义管理命令,这将避免所有这些问题。
You need to run
python manage.py shell
from the project directory, this loads the various django specific variables in your shell and will prevent theImportError
.EDIT:
Running it from a batch file and running it from the shell are not the same thing, which is why you are getting these errors.
The easiest way to solve the problem is to create a custom management command, which will avoid all these problems.