m2 Mac で mysqlclient のインストールが ld: library not found for -lzlib で失敗する時の対応

2023-05-11 19:37 (1年前) ytyng
View in English

m2 の mac で

pip install mysqlclient

すると

      running build_ext
      building 'MySQLdb._mysql' extension
      creating build/temp.macosx-13-arm64-cpython-310
      creating build/temp.macosx-13-arm64-cpython-310/MySQLdb
      clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -I/opt/homebrew/opt/openssl/include -I/opt/homebrew/include -I/opt/homebrew/opt/zlib/include -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/opt/homebrew/Cellar/mysql/8.0.33/include/mysql -I/Users/yotsuyanagi/workspace/ranking-html-generator/.venv/include -I/opt/homebrew/opt/python@3.10/Frameworks/Python.framework/Versions/3.10/include/python3.10 -c MySQLdb/_mysql.c -o build/temp.macosx-13-arm64-cpython-310/MySQLdb/_mysql.o -std=c99
      clang -bundle -undefined dynamic_lookup -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -L/opt/homebrew/opt/openssl/lib -L/opt/homebrew/lib -L/opt/homebrew/opt/zlib/lib -I/opt/homebrew/opt/openssl/include -I/opt/homebrew/include -I/opt/homebrew/opt/zlib/include build/temp.macosx-13-arm64-cpython-310/MySQLdb/_mysql.o -L/opt/homebrew/Cellar/mysql/8.0.33/lib -L/opt/homebrew/opt/openssl@1.1/lib -lmysqlclient -lzlib -lresolv -o build/lib.macosx-13-arm64-cpython-310/MySQLdb/_mysql.cpython-310-darwin.so
      ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib/'
      ld: warning: directory not found for option '-L/usr/local/opt/openssl/lib/'
      ld: library not found for -lzlib
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      error: command '/usr/bin/clang' failed with exit code 1
      [end of output]

  note: This error originates from a subprocess, and is likely not a problem with pip.
error: legacy-install-failure

× Encountered error while trying to install package.
╰─> mysqlclient

note: This is an issue with the package mentioned above, not pip.
hint: See above for output from the failure.

このエラーが出てインストールに失敗した。

もともと、 .zshrc

BREW_PREFIX=$(brew --prefix)
export LDFLAGS="-L${BREW_PREFIX}/opt/openssl/lib -L${BREW_PREFIX}/lib"
export CPPFLAGS="-I${BREW_PREFIX}/opt/openssl/include -I${BREW_PREFIX}/include"

上記のような環境変数を設定していたが、下記のように追記したらインストールが成功した。 (下の2行が追加分)

BREW_PREFIX=$(brew --prefix)
export LDFLAGS="-L${BREW_PREFIX}/opt/openssl/lib -L${BREW_PREFIX}/lib"
export CPPFLAGS="-I${BREW_PREFIX}/opt/openssl/include -I${BREW_PREFIX}/include"
export MYSQLCLIENT_LDFLAGS="${LDFLAGS} -L${BREW_PREFIX}/opt/zlib/lib"
export MYSQLCLIENT_CFLAGS="${CPPFLAGS} -I${BREW_PREFIX}/opt/zlib/include"
% pip install mysqlclient
Collecting mysqlclient
  Using cached mysqlclient-2.1.1-cp310-cp310-macosx_13_0_arm64.whl
Installing collected packages: mysqlclient
Successfully installed mysqlclient-2.1.1

参考ページ:

https://github.com/Homebrew/homebrew-core/issues/130258

追記

後ほど

clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -isysroot /Library/Developer/CommandLineTools/SDKs/MacOSX13.sdk -I/opt/homebrew/opt/openssl/include -I/opt/homebrew/include -Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/opt/homebrew/opt/openssl/include -I/opt/homebrew/include -I/opt/homebrew/opt/zlib/include -I/Users/yotsuyanagi/workspace/manga-server-django/.venv/include -I/opt/homebrew/opt/python@3.9/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.macosx-13-arm64-cpython-39/MySQLdb/_mysql.o -std=c99
MySQLdb/_mysql.c:29:10: fatal error: 'mysql.h' file not found
#include "mysql.h"
       ^~~~~~~~~
1 error generated.
error: command '/usr/bin/clang' failed with exit code 1
[end of output]

このエラーが出るようになった。

mysql.h は、探してみると

/opt/homebrew/Cellar/mysql-client/8.0.33/include/mysql/
/opt/homebrew/Cellar/mysql/8.0.33/include/mysql/

ここにあったので、これも MYSQLCLINET_CFLAGS に入れたらビルドできた

BREW_PREFIX=$(brew --prefix)
export LDFLAGS="-L${BREW_PREFIX}/opt/openssl/lib -L${BREW_PREFIX}/lib"
export CPPFLAGS="-I${BREW_PREFIX}/opt/openssl/include -I${BREW_PREFIX}/include"
export MYSQLCLIENT_LDFLAGS="${LDFLAGS} -L${BREW_PREFIX}/opt/zlib/lib"
export MYSQLCLIENT_CFLAGS="${CPPFLAGS} -I${BREW_PREFIX}/opt/zlib/include -I${BREW_PREFIX}/Cellar/mysql/8.0.33/include/mysql"
現在未評価
タイトルとURLをコピー

コメント

アーカイブ

2024
2023
2022
2021
2020
2019
2018
2017
2016
2015
2014
2013
2012
2011