使用 pip 安装 mysqlclient 到 MacOS Bigsur 时出错

error when install mysqlclient using pip to MacOS Bigsur

我尝试了为mysql客户端错误

编写的常见解决方案

并且mysql服务器很好-运行。 但是错误没有被修复..

我收到 clang linker errorlibrary not found for -lzstd

    clang -bundle -undefined dynamic_lookup -L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/user/.asdf/installs/python/3.7.10/lib -L/usr/local/opt/llvm/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -L/usr/local/opt/readline/lib -L/usr/local/opt/readline/lib -L/Users/user/.asdf/installs/python/3.7.10/lib -L/usr/local/opt/llvm/lib -L/Library/Developer/CommandLineTools/SDKs/MacOSX.sdk/usr/lib -L/usr/local/opt/llvm/lib -I/usr/local/opt/llvm/include build/temp.macosx-11.2-x86_64-3.7/MySQLdb/_mysql.o -L/usr/local/Cellar/mysql/8.0.25_1/lib -lmysqlclient -lzstd -lresolv -o build/lib.macosx-11.2-x86_64-3.7/MySQLdb/_mysql.cpython-37m-darwin.so
ld: library not found for -lzstd
clang-12: error: linker command failed with exit code 1 (use -v to see invocation)
error: command 'clang' failed with exit status 1

在我的例子中,我没有 sudo 访问权限,所以为我的用户安装了 brew 检查您的 brew 是否不在默认位置 这样做是为了检查你在哪里安装了 brew

brew --prefix
output: Users/helloWorld/homebrew

使用上面的输出设置 ld 标志和 cpp 标志 例如对我来说,没有找到 ssl 和 zstd 库,所以这就是我所做的:

export LDFLAGS="-L/Users/helloWorld/homebrew/lib -L/Users/helloWorld/homebrew/opt/openssl/lib"

export CPPFLAGS="-I/Users/helloWorld/homebrew/include -I/Users/helloWorld/homebrew/opt/openssl/include" 

然后执行 pip 安装

pip3 install mysqlclient