我是Django的新手,正在尝试设置一个基本的Web应用程序,以连接到macOS上的MySQL。但是,我似乎无法让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'
这是相关设置。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 Server和Connector / C所描述的问题... https://dev.mysql.com/doc/refman/5.7/en/c-api-multiple-installations.html,但不确定如何处理。
答案 0 :(得分:1)
ld: library not found for -lssl
->缺少openssl软件包,最好是openssl开发软件包。
brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/