mac 安装 mysqlclient 后使用报错问题

一直报错所以一直尝试网上的方法,也不清楚哪些有效哪些无效了,就纯记录一下步骤了

安装mysql8(官网下载),

系统自带的python3.7,

brew 安装mysql-client、openssl,

添加path

# mysql
export PATH="$PATH":/usr/local/mysql/bin
export DYLD_LIBRARY_PATH=/usr/local/mysql/lib/:$DYLD_LIBRARY_PATH

# mysql-client
export PATH="/usr/local/opt/mysql-client/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
export CPPFLAGS="-I/usr/local/opt/mysql-client/include"

# openssl
export PATH="/usr/local/opt/openssl/bin:$PATH"
export LDFLAGS="-L/usr/local/opt/openssl/lib"
export CPPFLAGS="-I/usr/local/opt/openssl/include"
export LIBRARY_PATH="$LIBRARY_PATH:/usr/local/opt/openssl/lib/"

pip3最新的mysqlclient

增加软连接:

sudo ln -s /usr/local/mysql/lib/libmysqlclient.21.dylib /usr/local/lib/libmysqlclient.21.dylib

sudo ln -s /usr/local/mysql/lib/libssl.1.1.dylib /usr/local/lib/libssl.1.1.dylib

sudo ln -s /usr/local/mysql/lib/libcrypto.1.1.dylib /usr/local/lib/libcrypto.1.1.dylib

再记录:

因为上面的path问题会导致mac系统找不到某些依赖库

比如vscode,每次打开vscode会显示 “electron”无法打开,就是因为依赖库找不到了

所以path改为

# mysql
export PATH="$PATH":/usr/local/mysql/bin

# mysql-client
export PATH="/usr/local/opt/mysql-client/bin:$PATH"

# openssl
export PATH="/usr/local/opt/openssl/bin:$PATH"

这样再打开 vscode 就不会报错了,程序也能正常连接mysql,mysql服务也没有问题,OK 

你可能感兴趣的:(python)