没解决此问题
(venv) [root@VM-8-12-centos MYPROJECT-django20240830]# python3 manage.py runserver 0.0.0.0:8080
Exception in thread django-main-thread:
Traceback (most recent call last):
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/db/utils.py", line 111, in load_backend
return import_module('%s.base' % backend_name)
File "/usr/local/python3/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/gis/db/backends/mysql/base.py", line 5, in <module>
from .features import DatabaseFeatures
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/gis/db/backends/mysql/features.py", line 1, in <module>
from django.contrib.gis.db.backends.base.features import BaseSpatialFeatures
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/gis/db/backends/base/features.py", line 3, in <module>
from django.contrib.gis.db import models
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/gis/db/models/__init__.py", line 3, in <module>
import django.contrib.gis.db.models.functions # NOQA
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/gis/db/models/functions.py", line 3, in <module>
from django.contrib.gis.db.models.fields import BaseSpatialField, GeometryField
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/gis/db/models/fields.py", line 3, in <module>
from django.contrib.gis import forms, gdal
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/gis/forms/__init__.py", line 3, in <module>
from .fields import ( # NOQA
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/gis/forms/fields.py", line 2, in <module>
from django.contrib.gis.gdal import GDALException
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/gis/gdal/__init__.py", line 28, in <module>
from django.contrib.gis.gdal.datasource import DataSource
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/gis/gdal/datasource.py", line 36, in <module>
from ctypes import byref
File "/usr/local/python3/lib/python3.8/ctypes/__init__.py", line 7, in <module>
from _ctypes import Union, Structure, Array
ModuleNotFoundError: No module named '_ctypes'
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "/usr/local/python3/lib/python3.8/threading.py", line 932, in _bootstrap_inner
self.run()
File "/usr/local/python3/lib/python3.8/threading.py", line 870, in run
self._target(*self._args, **self._kwargs)
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/core/management/commands/runserver.py", line 110, in inner_run
autoreload.raise_last_exception()
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/utils/autoreload.py", line 87, in raise_last_exception
raise _exception[1]
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/core/management/__init__.py", line 375, in execute
autoreload.check_errors(django.setup)()
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/utils/autoreload.py", line 64, in wrapper
fn(*args, **kwargs)
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/apps/config.py", line 301, in import_models
self.models_module = import_module(models_module_name)
File "/usr/local/python3/lib/python3.8/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1014, in _gcd_import
File "<frozen importlib._bootstrap>", line 991, in _find_and_load
File "<frozen importlib._bootstrap>", line 975, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 671, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 843, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/auth/models.py", line 3, in <module>
from django.contrib.auth.base_user import AbstractBaseUser, BaseUserManager
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/contrib/auth/base_user.py", line 48, in <module>
class AbstractBaseUser(models.Model):
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/db/models/base.py", line 122, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/db/models/base.py", line 326, in add_to_class
value.contribute_to_class(cls, name)
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/db/models/options.py", line 207, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/utils/connection.py", line 15, in __getattr__
return getattr(self._connections[self._alias], item)
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/utils/connection.py", line 62, in __getitem__
conn = self.create_connection(alias)
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/db/utils.py", line 204, in create_connection
backend = load_backend(db['ENGINE'])
File "/root/MYPROJECT/backend/venv/lib/python3.8/site-packages/django/db/utils.py", line 122, in load_backend
raise ImproperlyConfigured(
django.core.exceptions.ImproperlyConfigured: 'django.contrib.gis.db.backends.mysql' isn't an available database backend or couldn't be imported. Check the above exception. To use one of the built-in backends, use 'django.db.backends.XXX', where XXX is one of:
'mysql', 'oracle', 'postgresql', 'sqlite3'
=======================================================
=================================
[root@VM-8-12-centos django20240830]# pip list
Package Version
------------------- ----------
asgiref 3.8.1
bleach 3.1.5
certifi 2020.4.5.2
cffi 1.17.0
chardet 3.0.4
colorama 0.4.3
cryptography 43.0.0
Django 3.2.18
django-cors-headers 4.3.1
django-guardian 2.4.0
django-model-utils 4.2.0
django-redis 5.1.0
djangorestframework 3.14.0
docutils 0.16
download 0.3.5
GDAL 3.4.1
idna 2.9
jeepney 0.8.0
keyring 21.2.1
numpy 1.24.4
packaging 20.4
Pillow 8.4.0
pip 24.2
pkginfo 1.5.0.1
pycparser 2.22
Pygments 2.6.1
PyMySQL 1.1.1
pyparsing 2.4.7
pytz 2022.7.1
pywin32-ctypes 0.2.0
readme-renderer 26.0
redis 3.5.3
requests 2.24.0
requests-toolbelt 0.9.1
rfc3986 1.4.0
SecretStorage 3.3.3
setuptools 70.1.0
six 1.15.0
sqlparse 0.4.3
tqdm 4.47.0
twine 3.2.0
typing_extensions 4.1.1
urllib3 1.25.9
uWSGI 2.0.26
webencodings 0.5.1
wheel 0.43.0
xlrd 1.2.0
xlwt 1.3.0
(venv) [root@VM-8-12-centos django20240830]#
=================================
# yum install mysql-gis
Loaded plugins: fastestmirror, langpacks
Repository epel is listed more than once in the configuration
Loading mirror speeds from cached hostfile
epel | 4.3 kB 00:00:00
extras | 2.9 kB 00:00:00
os | 3.6 kB 00:00:00
updates | 2.9 kB 00:00:00
No package mysql-gis available.
Error: Nothing to do
=================================
然后,您可以登录到MySQL,并检查GIS扩展是否已经安装:
mysql -u root -p登录后,运行以下SQL命令:
SHOW PLUGINS;查找geometry
插件,如果其状态为ACTIVE
,则表示GIS扩展已成功安装并启用。
=================================
MySQL支持以下数据类型:
Geometry:可以存储所有的几何类型
Point:简单点
LINESTRING:简单线
POLYGON:简单面
MULITIPOINT:多点
MULITILINESTRING:多线
MUILITIPOLYGON:多面
GEOMETRYCOLLECTION:任何几何集合
标签:available,core,lib,py,django,File,line,backend From: https://www.cnblogs.com/emanlee/p/18389425