【问题标题】:MySQLClient won't install via pip on Macbook Pro M1 with latest version of Big SurMySQLClient 不会通过 pip 在最新版本的 Big Sur 的 Macbook Pro M1 上安装
【发布时间】:2021-06-07 18:21:12
【问题描述】:

我刚刚购买了一台带有 M1 芯片的新 Macbook Pro,并确保 Homebrew 可以在其上本地运行。我可以 pip 安装除 mysqlclient 之外的任何其他库,并且通过自制软件安装它没有问题,所以我从下面的错误消息中想知道,这是 mysqlclient 没有针对最新版本的 Big 更新的问题吗Sur,或者这是新 Mac 本身的问题?只要知道这对我来说将是一个很好的开始,如果您对如何解决它有建议,那就更好了!谢谢!

ERROR: Command errored out with exit status 1:
     command: /Users/danieljonathanschaefer/Desktop/work/401GOVE/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-install-bifqtsix/mysqlclient_6f9d0caea513420ea2052d60956aab6d/setup.py'"'"'; __file__='"'"'/private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-install-bifqtsix/mysqlclient_6f9d0caea513420ea2052d60956aab6d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-record-ukcglom_/install-record.txt --single-version-externally-managed --compile --install-headers /Users/danieljonathanschaefer/Desktop/work/401GOVE/include/site/python3.9/mysqlclient
         cwd: /private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-install-bifqtsix/mysqlclient_6f9d0caea513420ea2052d60956aab6d/
    Complete output (43 lines):
    mysql_config --version
    ['8.0.25']
    mysql_config --libs
    ['-L/opt/homebrew/Cellar/mysql/8.0.25_1/lib', '-lmysqlclient', '-lz', '-lzstd', '-lssl', '-lcrypto', '-lresolv']
    mysql_config --cflags
    ['-I/opt/homebrew/Cellar/mysql/8.0.25_1/include/mysql']
    ext_options:
      library_dirs: ['/opt/homebrew/Cellar/mysql/8.0.25_1/lib']
      libraries: ['mysqlclient', 'zstd', 'resolv']
      extra_compile_args: ['-std=c99']
      extra_link_args: []
      include_dirs: ['/opt/homebrew/Cellar/mysql/8.0.25_1/include/mysql']
      extra_objects: []
      define_macros: [('version_info', "(2,0,3,'final',0)"), ('__version__', '2.0.3')]
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.9-x86_64-3.9
    creating build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb
    creating build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-x86_64-3.9/MySQLdb/constants
    running build_ext
    building 'MySQLdb._mysql' extension
    creating build/temp.macosx-10.9-x86_64-3.9
    creating build/temp.macosx-10.9-x86_64-3.9/MySQLdb
    gcc -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch x86_64 -g -I/opt/homebrew/opt/openssl@1.1/include -Dversion_info=(2,0,3,'final',0) -D__version__=2.0.3 -I/opt/homebrew/Cellar/mysql/8.0.25_1/include/mysql -I/Users/danieljonathanschaefer/Desktop/work/401GOVE/include -I/Library/Frameworks/Python.framework/Versions/3.9/include/python3.9 -c MySQLdb/_mysql.c -o build/temp.macosx-10.9-x86_64-3.9/MySQLdb/_mysql.o -std=c99
    gcc -bundle -undefined dynamic_lookup -arch x86_64 -g -L/opt/homebrew/opt/openssl@1.1/lib -I/opt/homebrew/opt/openssl@1.1/include build/temp.macosx-10.9-x86_64-3.9/MySQLdb/_mysql.o -L/opt/homebrew/Cellar/mysql/8.0.25_1/lib -lmysqlclient -lzstd -lresolv -o build/lib.macosx-10.9-x86_64-3.9/MySQLdb/_mysql.cpython-39-darwin.so
    ld: library not found for -lzstd
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command '/usr/bin/gcc' failed with exit code 1
    ----------------------------------------
ERROR: Command errored out with exit status 1: /Users/danieljonathanschaefer/Desktop/work/401GOVE/bin/python3 -u -c 'import io, os, sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-install-bifqtsix/mysqlclient_6f9d0caea513420ea2052d60956aab6d/setup.py'"'"'; __file__='"'"'/private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-install-bifqtsix/mysqlclient_6f9d0caea513420ea2052d60956aab6d/setup.py'"'"';f = getattr(tokenize, '"'"'open'"'"', open)(__file__) if os.path.exists(__file__) else io.StringIO('"'"'from setuptools import setup; setup()'"'"');code = f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/ht/p0kw7_d11ns61kqmpmfcy6b40000gn/T/pip-record-ukcglom_/install-record.txt --single-version-externally-managed --compile --install-headers /Users/danieljonathanschaefer/Desktop/work/401GOVE/include/site/python3.9/mysqlclient Check the logs for full command output.

【问题讨论】:

  • 它在抱怨 libzstd,它是一个 zlib 压缩库。尝试“brew install zstd”,看看情况是否有所改善。
  • @TimRoberts 我已经安装了它,问题是它连接到我的虚拟环境中的 python 文件,而不是我的主机上 zstd 所在的文件。我过去从未遇到过这个问题,但也许新芯片或新更新改变了与此相关的一些东西。

标签: python pip homebrew mysql-connector macos-big-sur


【解决方案1】:

我在带有 M1 芯片的 Mac Pro 中遇到了同样的问题,然后我使用 brew install zstd 安装 zstd 然后安装 mysqlclint CFLAGS="-I$(brew --prefix)/include" LDFLAGS="-L$(brew --prefix)/lib" pip install mysqlclient

来源:https://github.com/PyMySQL/mysqlclient/issues/497

【讨论】:

    【解决方案2】:

    我遇到了同样的问题,我找到了这个命令,

    brew install mysql-client

    来源:https://doesitarm.com/formula/mysql-client/

    【讨论】:

      【解决方案3】:

      是的,当我尝试在运行 Monterey 12.0.1 和 Apple Silicon M1 芯片的 MacBook Pro 2021 上执行 pip install mysqlclient 时遇到了同样的问题。

      我使用了 Github 用户 jcbloch 在链接 https://github.com/PyMySQL/mysqlclient/issues/496 的讨论中找到的解决方案,这是我在阅读了我在 sathira lamalanswer 中找到的 https://github.com/PyMySQL/mysqlclient/issues/497 链接后发现的。

      我从阅读 jcbloch 的解释中了解到,问题在于当前带有 Monterey 12.0.1 的 MacBook Pro 2021 附带的 Python。该 Python 是为 x86_64 架构构建的。然而,mysqlclient 库有一个可用的 arm64 版本,如果您执行brew install mysql-client 之类的操作,默认情况下将获得该版本。

      使用file 命令显示问题:

      $ file /Library/Frameworks/Python.framework/Versions/2.7/bin/python
      /Library/Frameworks/Python.framework/Versions/2.7/bin/python: Mach-O 64-bit executable x86_64
      

      上面的文字显示pythonx86_64

      $ file /opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib 
      /opt/homebrew/opt/mysql-client/lib/libmysqlclient.21.dylib: Mach-O 64-bit dynamically linked shared library arm64
      

      上面的文字显示libmysqlclient.21.dylibarm64

      为了解决这个问题,Github 用户 jcbloch 创建了一个替代的 Homebrew 安装,它设置为使用 x86_64 架构,使用它来安装 MySQL 客户端库的 x86_64 版本,然后在将 MySQL 客户端安装到 Python 时使用该库通过pip.

      这是我必须做的,这与 jcbloch 建议的基本相同。

      不同的是,我确保包括卸载任何 mysqlclient python 包并删除所有缓存的 pip 库,这样您就不会再次重新安装缓存的错误包。而且,我最终得到了比 jcbloch 稍晚版本的 MySQL 客户端。而且,我必须包含一个 LDFLAGS 变量来指向 x86_64 openssl 库。

      在执行这些命令之前,请务必仔细检查以下所有路径。因为我在上一个命令中复制并粘贴了错误版本的 mysql 库,所以我出轨了好几个小时。

      cd /opt
      mkdir homebrew-x86 
      curl -L https://github.com/Homebrew/brew/tarball/master | tar xz --strip 1 -C homebrew-x86
      arch -x86_64 homebrew-x86/bin/brew install mysql-client@5.7
      rm -rf ~/Library/Caches/pip
      pip uninstall mysqlclient
      export PATH="/opt/homebrew-x86/opt/mysql-client@5.7/bin:$PATH"
      CPPFLAGS="-I/opt/homebrew-x86/opt/openssl@1.1/include" LDFLAGS="-L/opt/homebrew-x86/opt/openssl@1.1/lib" MYSQLCLIENT_CFLAGS="-I/opt/homebrew-x86/Cellar/mysql-client@5.7/5.7.32/include/mysql" MYSQLCLIENT_LDFLAGS="-L/opt/homebrew-x86/Cellar/mysql-client@5.7/5.7.32/lib -lmysqlclient" arch -x86_64 pip install -I -vvv mysqlclient
      

      然后,再次按照 jcbloch 的建议,我通过检查 mysql_affected_rows 符号是否存在来验证安装。我猜这个符号只存在于x86_64架构版本的MySQL客户端中。

      $ sudo symbols homebrew-x86/Cellar/mysql-client@5.7/5.7.34/lib/libmysqlclient.dylib -arch x86_64 | grep mysql_affected_rows
             0x0000000000003fe7 (     0xd) mysql_affected_rows [FUNC, EXT, NameNList, MangledNameNList, Merged, NList, FunctionStarts]
      

      【讨论】:

      • 在较新的 mac 上,python3.9 预装在 /opt/homebrew/bin/python3.9 上,它已经是 arch arm64,所以你不需要所有这些来强制 x86。我最初来到这里是因为我试图用 python3.7 运行它,但你的回答给了我这个想法。 :)
      • 不幸的是,我需要 python 2。是的,我知道,那是黑暗时代。
      【解决方案4】:

      看看这个link

      我使用的是 M1 Macbook,我遇到了同样的问题 我使用 django 4.0.1 和 python 3.10 用 PyMySQL 解决了这个问题

      【讨论】:

      • 虽然此链接可能会回答问题,但最好在此处包含答案的基本部分并提供链接以供参考。如果链接页面发生更改,仅链接答案可能会失效。 - From Review
      猜你喜欢
      • 2021-05-08
      • 2021-03-04
      • 2021-11-07
      • 2021-05-25
      • 1970-01-01
      • 2023-03-26
      • 1970-01-01
      • 2022-01-18
      • 2023-02-20
      相关资源
      最近更新 更多