【发布时间】:2018-12-13 01:32:39
【问题描述】:
我是 Django 新手,正在尝试在 macOS 上设置一个连接到 MySQL 的基本 Web 应用程序。但是,我似乎无法让 mysqlclient 在 macOS 上工作。
我正在运行一个虚拟环境和以下版本:
$ brew --version
Homebrew 1.8.5
$ pip --version
pip 18.1
$ python --version
Python 3.7.1
$ mysql --version
mysql Ver 8.0.12 for osx10.14 on x86_64 (Homebrew)
当我尝试pip install mysqlclient (https://pypi.org/project/mysqlclient/) 时,我得到了
ld: library not found for -lssl
clang: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'gcc' failed with exit status 1
根据文档“您可能需要像这样安装 Python 和 MySQL 开发头文件和库:”
$ brew install mysql-connector-c
这给出了另一个错误:
Error: Cannot install mysql-connector-c because conflicting formulae are installed.
mysql: because both install MySQL client libraries
Please `brew unlink mysql` before continuing.
$ brew unlink mysql
$ brew install mysql-connector-c
==> Pouring mysql-connector-c-6.1.11.mojave.bottle.tar.gz
???? /usr/local/Cellar/mysql-connector-c/6.1.11: 79 files, 15.3MB
brew link mysql
Error: Could not symlink bin/my_print_defaults
Target /usr/local/bin/my_print_defaults
is a symlink belonging to mysql-connector-c
$ brew link --overwrite mysql
现在我可以从控制台启动 mysql,但是当我更新 django,mysite settings.py 以连接到 MySQL 时,我得到了
ModuleNotFoundError: No module named 'MySQLdb'
这里是相关的settings.py
DATABASES = {
'default': {
'ENGINE': 'django.db.backends.mysql',
'NAME': 'django',
'USER': 'root',
'PASSWORD': 'XXXXXX',
'HOST': 'localhost',
'PORT': '3306',
}
}
我还根据错误报告 https://bugs.mysql.com/bug.php?id=86971 检查了 mysql_config
Usage: /usr/local/bin/mysql_config [OPTIONS]
Compiler: Clang 10.0.0.10001145
Options:
--cflags [-I/usr/local/Cellar/mysql/8.0.12/include/mysql ]
--cxxflags [-I/usr/local/Cellar/mysql/8.0.12/include/mysql ]
--include [-I/usr/local/Cellar/mysql/8.0.12/include/mysql]
--libs [-L/usr/local/Cellar/mysql/8.0.12/lib -lmysqlclient -lssl -lcrypto]
--libs_r [-L/usr/local/Cellar/mysql/8.0.12/lib -lmysqlclient -lssl -lcrypto]
--plugindir [/usr/local/Cellar/mysql/8.0.12/lib/plugin]
--socket [/tmp/mysql.sock]
--port [0]
--version [8.0.12]
--variable=VAR VAR is one of:
pkgincludedir [/usr/local/Cellar/mysql/8.0.12/include/mysql]
pkglibdir [/usr/local/Cellar/mysql/8.0.12/lib]
plugindir [/usr/local/Cellar/mysql/8.0.12/lib/plugin]
我尝试了许多不同的解决方案,但到目前为止都没有运气。感觉就像我要掉进一个兔子洞 - 非常感谢任何帮助;)
我查看了以下页面上的建议解决方案,但还没有解决方案:
- MySQL-python install Mac
- error: command 'x86_64-linux-gnu-gcc' when installing mysqlclient
- MySQL-python install Mac
我怀疑这个问题是由于同时安装 MySQL 服务器和连接器/C 中描述的问题...https://dev.mysql.com/doc/refman/5.7/en/c-api-multiple-installations.html 但不知道该怎么办。
【问题讨论】: