我正在使用 django 1.6b 和 python 3.3,我得到这个导入错误,
./manage.py runserver
Validating models...
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x104ae4d40>
Traceback (most recent call last):
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/utils/autoreload.py", line 93, in wrapper
fn(*args, **kwargs)
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/core/management/commands/runserver.py", line 97, in inner_run
self.validate(display_num_errors=True)
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/core/management/base.py", line 308, in validate
num_errors = get_validation_errors(s, app)
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/core/management/validation.py", line 34, in get_validation_errors
for (app_name, error) in get_app_errors().items():
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/db/models/loading.py", line 196, in get_app_errors
self._populate()
File "/opt/boxen/pyenv/version/side-project/lib/python3.3/site-packages/django/db/models/loading.py", line 78, in _populate
self.load_app(app_name)
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/db/models/loading.py", line 99, in load_app
models = import_module('.models', app_name)
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/utils/importlib.py", line 35, in import_module
__import__(name)
File "/Users/moi/Projects/sos/dealerships/models.py", line 4, in <module>
from django.contrib.gis.db import models # as geomodels
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/contrib/gis/db/models/__init__.py", line 8, in <module>
from django.contrib.gis.db.models.manager import GeoManager
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/contrib/gis/db/models/manager.py", line 2, in <module>
from django.contrib.gis.db.models.query import GeoQuerySet
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/contrib/gis/db/models/query.py", line 6, in <module>
from django.contrib.gis.db.models.fields import get_srid_info, PointField, LineStringField
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/contrib/gis/db/models/fields.py", line 4, in <module>
from django.contrib.gis import forms
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/contrib/gis/forms/__init__.py", line 2, in <module>
from .fields import (GeometryField, GeometryCollectionField, PointField,
File "/opt/boxen/pyenv/versions/side-project/lib/python3.3/site-packages/django/contrib/gis/forms/fields.py", line 11, in <module>
from django.contrib.gis.geos import GEOSException, GEOSGeometry, fromstr
ImportError: cannot import name GEOSException
这是我为 gis 准备的唯一代码,
from django.contrib.gis.db import models as geomodels
from django.utils.translation import ugettext as _
from django.contrib.localflavor.us.models import USStateField
class UsLocation(geomodels.Model):
address_1 = geomodels.CharField(_("address"), max_length=128)
address_2 = geomodels.CharField(_("address cont'd"), max_length=128, blank=True)
city = geomodels.CharField(_("city"), max_length=64, default="Kansas City")
state = USStateField(_("state"), default="KO")
zip_code = geomodels.CharField(_("zip code"), max_length=5, default="16874")
现在我不会为我的地址模型使用 gis 助手,但我不确定是什么导致了这个导入异常。我检查了 django 1.5/1.6 版本,它们具有相同的行。我想知道它是否与我使用 1.6bw/python 3.3.2 有关?