我正在添加django-location-field。但是,当我添加以下代码
from django.contrib.gis.geos import Point
from location_field.models.spatial import LocationField
address = map_fields.AddressField(max_length=200, blank=True)
location = LocationField(based_fields=['city'], zoom=7, default=Point(1.0, 1.0))
与自述教程相同,它会引发错误
python3 manage.py runserver
Unhandled exception in thread started by <function check_errors.<locals>.wrapper at 0x7efbe781bd90>
Traceback (most recent call last):
...
from django.contrib.gis import gdal
File "/home/samuel/.local/lib/python3.6/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "/home/samuel/.local/lib/python3.6/site-packages/django/contrib/gis/gdal/datasource.py", line 41, in <module>
from django.contrib.gis.gdal.layer import Layer
File "/home/samuel/.local/lib/python3.6/site-packages/django/contrib/gis/gdal/layer.py", line 6, in <module>
from django.contrib.gis.gdal.feature import Feature
File "/home/samuel/.local/lib/python3.6/site-packages/django/contrib/gis/gdal/feature.py", line 4, in <module>
from django.contrib.gis.gdal.geometries import OGRGeometry, OGRGeomType
File "/home/samuel/.local/lib/python3.6/site-packages/django/contrib/gis/gdal/geometries.py", line 52, in <module>
from django.contrib.gis.geometry import hex_regex, json_regex, wkt_regex
ImportError: cannot import name 'hex_regex'
我已经尝试过在线检查是否有与此包相关的任何类似问题,但没有发现任何问题。
我在virtualenv上将django 2.1.2与python 3一起使用。 这是点子冻结的结果
apsw==3.16.2.post1
asn1crypto==0.24.0
attrs==17.4.0
Automat==0.6.0
Babel==2.6.0
BeautifulSoup==3.2.1
beautifulsoup4==4.6.0
certifi==2018.4.16
chardet==3.0.4
CherryPy==8.9.1
click==6.7
cloudinary==1.12.0
colorama==0.3.7
configobj==5.0.6
confusable-homoglyphs==3.1.1
constantly==15.1.0
cryptography==2.1.4
cssselect==1.0.3
cssutils==1.0.2
defer==1.0.6
defusedxml==0.5.0
deluge==1.3.15
dj-database-url==0.5.0
Django==1.11.14
django-appconf==1.0.2
django-background-image==0.0.1
django-bootstrap==0.2.4
django-bootstrap4==0.0.6
django-compressor==2.2
django-decouple==2.1
django-extra-views==0.11.0
django-haystack==2.8.1
django-heroku==0.3.1
django-live-support==0.1.9
django-mathfilters==0.4.0
django-oscar==1.6.4
django-phonenumber-field==2.0.0
django-registration==2.4.1
django-tables2==1.21.2
django-treebeard==4.3
django-widget-tweaks==1.4.2
dnspython==1.15.0
enum34==1.1.6
factory-boy==2.11.1
Faker==0.9.0
feedparser==5.2.1
funcsigs==1.0.2
gunicorn==19.9.0
gyp==0.1
heroku==0.1.4
html5-parser==0.4.4
html5lib==0.999999999
httplib2==0.9.2
hyperlink==17.3.1
idna==2.7
incremental==16.10.1
ipaddress==1.0.17
keyring==10.6.0
keyrings.alt==3.0
lxml==4.2.1
Markdown==2.6.9
mechanize==0.2.5
mock==2.0.0
msgpack==0.5.6
netifaces==0.10.4
numpy==1.13.3
olefile==0.45.1
PAM==0.4.2
pbr==4.1.1
phonenumbers==8.9.10
phonenumberslite==8.9.10
Pillow==5.2.0
PinguyBuilder-gtk==5.1.post6
psycopg2==2.7.5
psycopg2-binary==2.7.5
purl==1.4
pyasn1==0.4.2
pyasn1-modules==0.2.1
pycairo==1.16.2
pycrypto==2.6.1
pycurl==7.43.0.1
pygame===1.9.1release
Pygments==2.2.0
pygobject==3.26.1
pyliblzma==0.5.3
pyOpenSSL==17.5.0
pyparsing==2.2.0
pyquery==1.2.9
pyserial==3.4
python-apt==1.6.1
python-dateutil==2.7.3
python-debian==0.1.32
python-libtorrent==1.1.5
pytz==2018.5
pyxdg==0.25
PyYAML==3.12
rcssmin==1.0.6
regex==2017.12.12
repoze.lru==0.7
requests==2.19.1
rjsmin==1.0.12
Routes==2.4.1
SecretStorage==2.3.1
service-identity==16.0.0
simplejson==3.16.0
six==1.11.0
SOAPpy==0.12.22
sorl-thumbnail==12.4.1
text-unidecode==1.2
Twisted==17.9.0
ubuntu-cleaner==1.0.4
Unidecode==1.0.22
urllib3==1.23
uTidylib==0.3
variety==0.6.9
virtualenv==16.0.0
webencodings==0.5
WebOb==1.7.3
whitenoise==3.3.1
wstools==0.4.3
wxBanker==1.0.0
wxPython==3.0.2.0
wxPython-common==3.0.2.0
xmltodict==0.11.0
zope.interface==4.3.2
答案 0 :(得分:0)
是的,所以我也遇到了这个问题。您需要卸载Django并重新安装。那或吹走您的virtualenv并重新创建它。两种情况都确保您安装了Django2。
pip uninstall -y Django
pip install Django==2.2