无法在Mojave上为Mac安装mysqlclient

时间:2019-05-08 06:18:11

标签: python mysql django mysql-connector mysql-connector-python

我在Web应用程序中使用Python + Django + MySql。 每当我尝试安装mysqlclient时,我都会得到多个错误。

现在我被困在这里:

我跑的时候 pip install mysqlclient我遇到以下错误:

enter image description here

enter image description here

错误文本日志:https://pastebin.com/VrTGgpnr

2 个答案:

答案 0 :(得分:1)

您可以按照以下步骤操作,如果系统中已经安装了brew和MySQL,请跳过步骤1 步骤2

第一步:安装Brew

您需要在本地计算机上安装Homebrew。您可以通过以下方式实现:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

步骤Twp:安装MySQL

使用 Homebrew ,您可以通过以下方式简单地安装 mysql

brew install mysql

然后使用以下命令在MySQL服务器中设置凭据:

mysql_secure_installation

最后,如果要从登录开始并作为后台服务,请运行以下命令:

brew services start mysql

其他

mysql.server start

第三步:安装MySQL-Connector-C

要将其他任何应用程序连接到MySQL,则需要安装连接器。您可以这样做:

brew install mysql-connector-c

然后根据mysqlclient's文档,您需要在mysql_config处进行错误修复。为此,请在终端中输入mysql_config

>> mysql_config
Usage: /usr/local/bin/mysql_config [OPTIONS]
Compiler: ...

它将显示您需要在哪里找到mysql_config。然后,您可以使用自己喜欢的任何编辑器,并在mysql_config内更改以下几行:

更改

# on macOS, on or about line 112:
# Create options
libs="-L$pkglibdir"
libs="$libs -l "

收件人

# Create options
libs="-L$pkglibdir"
libs="$libs -lmysqlclient -lssl -lcrypto"

第四步:安装XCode-Select

您可以通过以下方式实现:

xcode-select --install

第五步:安装OpenSSL

请运行以下命令:

brew install openssl

然后使用以下行将其路径添加到环境:

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

第六步:取消链接MySQL并链接MySQL-Connector-C

您需要取消链接 mysql 并链接 mysql-connector-c

brew unlink mysql
brew link --overwrite mysql-connector-c

第七步:安装MySQLClient

您应该能够正确使用pip install mysqlclient

步骤8:再次将MySQL重新链接

现在,您需要执行与第六步相反的操作:

brew unlink mysql-connector-c
brew link --overwrite mysql

希望mysqlclient现在可以正常工作,并且将应用程序从mysql连接到django不会有问题。

仅供参考,我在this blog post中也写了差不多的东西。

答案 1 :(得分:0)

您可以使用官方的MySQL Connector / Python。

pip install mysql-connector-python

您不需要安装OpenSSL或任何其他库。

有关安装https://dev.mysql.com/doc/dev/connector-python/8.0/installation.html

的更多详细信息

以下是配置您的应用的方法:https://dev.mysql.com/doc/connector-python/en/connector-python-django-backend.html

相关问题