首先自行安装好brew命令
- 安装gcc (我切换为阿里源才安装成功的)
brew install gcc
- 安装openssl
brew install openssl
安装完后有提示,我们需要把目录添加环境变量: 把下面的设置环境变量追加到 ~/.bash_profile
export LDFLAGS="-L/opt/homebrew/opt/openssl@3/lib"
export CPPFLAGS="-I/opt/homebrew/opt/openssl@3/include"
- 安装mysql-connector-c
brew install mysql-connector-c
根据提示可以设置下环境变量,我是安装了 mysql,配置了下面的,没配置提示说的
export PATH=${PATH}:/usr/local/mysql/bin
4. 安装mysqlclient
source ~/.bash_profile
pip install mysqlclient
我是碰见了下面的报错:
clang -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -Wl,-headerpad,0x1000 -L/opt/homebrew/opt/openssl@3/lib -I/opt/homebrew/opt/openssl@3/include build/temp.macosx-10.14-arm64-3.8/MySQLdb/_mysql.o -L/opt/homebrew/opt/mysql-client/lib -lmysqlclient -lzstd -lresolv -o build/lib.macosx-10.14-arm64-3.8/MySQLdb/_mysql.cpython-38-darwin.so ld: library not found for -lzstd clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command ‘clang’ failed with exit status 1 ---------------------------------------- ERROR: Failed building wheel for mysqlclient
解决办法:
brew reinstall zstd
执行这个安装语句:
CFLAGS="-I$(brew --prefix)/include" LDFLAGS="-L$(brew --prefix)/lib" pip3 install mysqlclient
|