Search code examples
mysqlpipclangzstd

error when install mysqlclient using pip to MacOS Bigsur


I've tried common solutions written for mysqlclient error

  • 1st try: brew install mysql-connector-c
  • 2nd try: LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient
  • 3rd try: brew install zstd

And mysql server is well-running. But the error is not being fixed..

I am getting clang linker error saying library 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

Solution

  • In my case I did not had the sudo access so installed brew for my user Check if your brew is not in default location do this to check where you have installed brew

    brew --prefix
    output: Users/helloWorld/homebrew
    

    use the output of above to set the ld flags and cpp flags for example for me ssl and zstd libs were not found so this is what i did:

    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" 
    

    and then do the pip install

    pip3 install mysqlclient