我安装Django并尝试连接到MySQL并运行迁移,但出现错误“您安装了mysqlclient吗?”。
我该怎么办?
我正在使用venv,我的python版本是3.7.4,对于x86_64(Homebrew)上的osx10.14,mysql是Ver 8.0.17。 这是点子列表
Package Version
------------------- -----------
beautifulsoup4 4.6.0
certifi 2019.6.16
chardet 3.0.4
Django 2.2.5
django-modelcluster 4.4
django-taggit 0.24.0
django-treebeard 4.3
djangorestframework 3.10.2
draftjs-exporter 2.1.6
entrypoints 0.3
flake8 3.7.4
html5lib 1.0.1
idna 2.8
mccabe 0.6.1
mysqlclient 1.4.2.post1
Pillow 6.1.0
pip 19.0.3
pycodestyle 2.5.0
pyflakes 2.1.1
pytz 2019.2
requests 2.22.0
setuptools 40.8.0
six 1.12.0
sqlparse 0.3.0
Unidecode 1.1.1
urllib3 1.25.3
wagtail 2.6.1
wagtailcodeblock 1.15.0.0
webencodings 0.5.1
Willow 1.1
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'local_test',
'USER': 'root',
'PASSWORD': 'root',
'HOST': '',
'PORT': '',
'OPTIONS': {
'charset': 'utf8mb4',
}
}
}
Traceback (most recent call last):
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 15, in <module>
import MySQLdb as Database
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/MySQLdb/__init__.py", line 18, in <module>
from . import _mysql
ImportError: dlopen(/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Library not loaded: @rpath/libssl.1.0.0.dylib
Referenced from: /Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/MySQLdb/_mysql.cpython-37m-darwin.so
Reason: image not found
The above exception was the direct cause of the following exception:
Traceback (most recent call last):
File "../manage.py", line 10, in <module>
execute_from_command_line(sys.argv)
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 381, in execute_from_command_line
utility.execute()
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/core/management/__init__.py", line 357, in execute
django.setup()
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/__init__.py", line 24, in setup
apps.populate(settings.INSTALLED_APPS)
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/apps/registry.py", line 114, in populate
app_config.import_models()
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/apps/config.py", line 211, in import_models
self.models_module = import_module(models_module_name)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "<frozen importlib._bootstrap>", line 1006, in _gcd_import
File "<frozen importlib._bootstrap>", line 983, in _find_and_load
File "<frozen importlib._bootstrap>", line 967, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 677, in _load_unlocked
File "<frozen importlib._bootstrap_external>", line 728, in exec_module
File "<frozen importlib._bootstrap>", line 219, in _call_with_frames_removed
File "/Users/bicepper/PycharmProjects/test-project/test/base/models.py", line 3, in <module>
from modelcluster.models import ClusterableModel
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/modelcluster/models.py", line 153, in <module>
class ClusterableModel(models.Model):
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/db/models/base.py", line 117, in __new__
new_class.add_to_class('_meta', Options(meta, app_label))
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/db/models/base.py", line 321, in add_to_class
value.contribute_to_class(cls, name)
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/db/models/options.py", line 204, in contribute_to_class
self.db_table = truncate_name(self.db_table, connection.ops.max_name_length())
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/db/__init__.py", line 28, in __getattr__
return getattr(connections[DEFAULT_DB_ALIAS], item)
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/db/utils.py", line 201, in __getitem__
backend = load_backend(db['ENGINE'])
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/db/utils.py", line 110, in load_backend
return import_module('%s.base' % backend_name)
File "/Library/Frameworks/Python.framework/Versions/3.7/lib/python3.7/importlib/__init__.py", line 127, in import_module
return _bootstrap._gcd_import(name[level:], package, level)
File "/Users/bicepper/PycharmProjects/test-project/venv/lib/python3.7/site-packages/django/db/backends/mysql/base.py", line 20, in <module>
) from err
django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module.
Did you install mysqlclient?
答案 0 :(得分:0)
激活venv并运行pip install mysql-python
。在安装pip install -U pip
库之前,请确保您已对venv进行过mysql-python
处理。
答案 1 :(得分:0)
我将使用mysqlclient
,可以与pip install mysqlclient
一起安装。
请确保您在虚拟环境中工作,并且可能不应该在同一环境中使用mysqlclient
和mysql-python
,否则可能会出现问题(不过我不确定)
我从没使用过mysql-python
,所以对于这个软件包我不能说太多。