Failed building wheel for mysqlclient on macOS.

huangapple go评论75阅读模式
英文:

Failed building wheel for mysqlclient on macOS

问题

I have been troubleshooting this problem for the past 3 days, tried every method in stack and no luck, I am relatively new to Django and python so any suggestions will be greatly appreciated.
所以我在过去的3天里一直在解决这个问题,尝试了堆栈中的每种方法,但没有成功,我对Django和Python相对较新,因此非常感谢任何建议。

so I have been having a problem with installing mysqlclient through "pipenv install mysqlclient"
因此,我在通过"pipenv install mysqlclient"安装mysqlclient时遇到了问题
returning: ERROR: Failed building wheel for mysqlclient
返回:错误:构建mysqlclient的轮失败

full summary:
完整的摘要:

Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
提示Pipenv发现自己正在虚拟环境中运行因此它将自动使用该环境而不是为任何项目创建自己的环境您可以设置PIPENV_IGNORE_VIRTUALENVS=1以强制pipenv忽略该环境并创建自己的环境您可以设置PIPENV_VERBOSITY=-1以抑制此警告
Installing mysqlclient...
正在安装mysqlclient...
Resolving mysqlclient...
正在解决mysqlclient...
Installing...
正在安装...
 Installing mysqlclient...[31m[1mError: [0m An error occurred while installing [32mmysqlclient[0m!
 正在安装mysqlclient...[31m[1m错误[0m在安装[32mmysqlclient[0m时发生错误
Error text: Collecting mysqlclient (from -r 
/var/folders/x4/6p57c76d173_b99bb3rtc2q40000gn/T/pipenv-rva1k23w-requirements/pipenv-xzl65j4d-requirement.txt (line 1))
错误文本-r 
/var/folders/x4/6p57c76d173_b99bb3rtc2q40000gn/T/pipenv-rva1k23w-requirements/pipenv-xzl65j4d-requirement.txt (第1行)收集mysqlclient
  Using cached mysqlclient-2.1.1.tar.gz (88 kB)
  正在使用缓存的mysqlclient-2.1.1.tar.gz88 kB
  Installing build dependencies: started
  安装构建依赖项已启动
  Installing build dependencies: finished with status 'done'
  安装构建依赖项已完成状态为完成
  Getting requirements to build wheel: started
  获取构建轮的要求已启动
  Getting requirements to build wheel: finished with status 'done'
  获取构建轮的要求已完成状态为完成
  Preparing metadata (pyproject.toml): started
  准备元数据pyproject.toml):已启动
  Preparing metadata (pyproject.toml): finished with status 'done'
  准备元数据pyproject.toml):已完成状态为完成
Building wheels for collected packages: mysqlclient
为收集的包构建轮mysqlclient
  Building wheel for mysqlclient (pyproject.toml): started
  为mysqlclientpyproject.toml构建轮已启动
  Building wheel for mysqlclient (pyproject.toml): finished with status 'error'
  构建mysqlclientpyproject.toml的轮已完成状态为错误
Failed to build mysqlclient
构建mysqlclient失败

[36m  error: subprocess-exited-with-error
  
  × Building wheel for mysqlclient (pyproject.toml) did not run successfully.
   exit code: 1
  ╰─> [45 lines of output]
      mysql_config --version
      ['8.0.33']
      mysql_config --libs
      ['-L/opt/homebrew/Cellar/mysql/8.0.33/lib', '-lmysqlclient', '-lzlib', '-lzstd', '-L/opt/homebrew/opt/openssl@1.1/lib', '-lssl', 
'-lcrypto', '-lresolv']
      mysql_config --cflags
      ['-I/opt/homebrew/Cellar/mysql/8.0.33/include/mysql']
      ext_options:
        library_dirs: ['/opt/homebrew/Cellar/mysql/8.0.33/lib', '/opt/homebrew/opt/openssl@1.1/lib']
        libraries: ['mysqlclient', 'zlib', 'resolv']
        extra_compile_args: ['-std=c99']
        extra_link_args: []
        include_dirs: ['/opt/homebrew/Cellar/mysql/8.0.33/include/mysql']
        extra_objects: []
        define_macros: [('version_info', '(2,1,1,'final',0)'), ('__version__', '2.1.1')]
      running bdist_wheel
      running build
      running build_py
      creating build
      creating build/lib.macosx-10.9-universal2-cpython-311
      creating build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
      copying MySQLdb/__init__.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
      copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
      copying MySQLdb/connections.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
      copying MySQLdb/converters.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
      copying MySQLdb/cursors.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
      copying MySQLdb/release.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
      copying MySQLdb/times.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
      creating build/lib.macosx-10.9-universal2-cpython-311/MySQLdb/constants
      copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb/constants
      copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-universal2-cpython-311/

<details>
<summary>英文:</summary>

I have been troubleshooting this problem for the past 3 days, tried every method in stack and no luck, I am relatively new to Django and python so any suggestions will be greatly appreciated.
so I have been having a problem with installing mysqlclient through &quot;pipenv install mysqlclient&quot;
returning:   `ERROR: Failed building wheel for mysqlclient`

full summary:


Courtesy Notice: Pipenv found itself running within a virtual environment, so it will automatically use that environment, instead of creating its own for any project. You can set PIPENV_IGNORE_VIRTUALENVS=1 to force pipenv to ignore that environment and create its own instead. You can set PIPENV_VERBOSITY=-1 to suppress this warning.
Installing mysqlclient...
Resolving mysqlclient...
Installing...
⠸ Installing mysqlclient...[31m[1mError: [0m An error occurred while installing [32mmysqlclient[0m!
Error text: Collecting mysqlclient (from -r
/var/folders/x4/6p57c76d173_b99bb3rtc2q40000gn/T/pipenv-rva1k23w-requirements/pipenv-xzl65j4d-requirement.txt (line 1))
Using cached mysqlclient-2.1.1.tar.gz (88 kB)
Installing build dependencies: started
Installing build dependencies: finished with status 'done'
Getting requirements to build wheel: started
Getting requirements to build wheel: finished with status 'done'
Preparing metadata (pyproject.toml): started
Preparing metadata (pyproject.toml): finished with status 'done'
Building wheels for collected packages: mysqlclient
Building wheel for mysqlclient (pyproject.toml): started
Building wheel for mysqlclient (pyproject.toml): finished with status 'error'
Failed to build mysqlclient

[36m error: subprocess-exited-with-error

× Building wheel for mysqlclient (pyproject.toml) did not run successfully.
│ exit code: 1
╰─> [45 lines of output]
mysql_config --version
['8.0.33']
mysql_config --libs
['-L/opt/homebrew/Cellar/mysql/8.0.33/lib', '-lmysqlclient', '-lzlib', '-lzstd', '-L/opt/homebrew/opt/openssl@1.1/lib', '-lssl',
'-lcrypto', '-lresolv']
mysql_config --cflags
['-I/opt/homebrew/Cellar/mysql/8.0.33/include/mysql']
ext_options:
library_dirs: ['/opt/homebrew/Cellar/mysql/8.0.33/lib', '/opt/homebrew/opt/openssl@1.1/lib']
libraries: ['mysqlclient', 'zlib', 'resolv']
extra_compile_args: ['-std=c99']
extra_link_args: []
include_dirs: ['/opt/homebrew/Cellar/mysql/8.0.33/include/mysql']
extra_objects: []
define_macros: [('version_info', "(2,1,1,'final',0)"), ('version', '2.1.1')]
running bdist_wheel
running build
running build_py
creating build
creating build/lib.macosx-10.9-universal2-cpython-311
creating build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
copying MySQLdb/init.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
copying MySQLdb/_exceptions.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
copying MySQLdb/connections.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
copying MySQLdb/converters.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
copying MySQLdb/cursors.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
copying MySQLdb/release.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
copying MySQLdb/times.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb
creating build/lib.macosx-10.9-universal2-cpython-311/MySQLdb/constants
copying MySQLdb/constants/init.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb/constants
copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb/constants
copying MySQLdb/constants/CR.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb/constants
copying MySQLdb/constants/ER.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb/constants
copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb/constants
copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.9-universal2-cpython-311/MySQLdb/constants
warning: build_py: byte-compiling is disabled, skipping.

  running build_ext
building &#39;MySQLdb._mysql&#39; extension
creating build/temp.macosx-10.9-universal2-cpython-311
creating build/temp.macosx-10.9-universal2-cpython-311/MySQLdb
clang -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -arch arm64 -arch x86_64 -g 

-Dversion_info=(2,1,1,'final',0) -D__version__=2.1.1 -I/opt/homebrew/Cellar/mysql/8.0.33/include/mysql
-I/Users/sonaallaibrahim/Desktop/storefront/my-test-env/include -I/Library/Frameworks/Python.framework/Versions/3.11/include/python3.11 -c
MySQLdb/_mysql.c -o build/temp.macosx-10.9-universal2-cpython-311/MySQLdb/_mysql.o -std=c99
clang -bundle -undefined dynamic_lookup -arch arm64 -arch x86_64 -g build/temp.macosx-10.9-universal2-cpython-311/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-10.9-universal2-cpython-311/MySQLdb/_mysql.cpython-311-darwin.so
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

note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
[0m
✘ Installation Failed

am using python 3.11
running on MacOS Ventura 13.3.1 M1 chip
as I said any suggestions will help a lot
tried uninstalling and reinstalling wheel
tried uninstalling and reinstalling mysql
tried unlinking mysql and link it back
tried brew mysql connector 
tried brew mysql-client
</details>
# 答案1
**得分**: 1
错误消息显示 `zlib` 未找到。这意味着要么库未安装,要么 Python 无法找到它。因此,首先要做的是安装该库。
```shell
brew install zlib

接下来,我们需要为 Python 设置一些环境变量,以便它能够在正确的文件夹中查找库。设置以下环境变量(或将它们添加到您的 .bashrc 文件中)。

export LDFLAGS="-L/usr/local/opt/zlib/lib"
export CPPFLAGS="-I/usr/local/opt/zlib/include"

zlib 的实际路径可能会有所不同(在此情况下为 /usr/local/opt/zlib)。您可以通过执行以下命令获取您机器上的路径:brew --prefix zlib

英文:

The error message says zlib is not found. It means either the library is not installed, or python is not able to find it. So the first thing to do is to install the library.

brew install zlib

Next, we need to set a couple of env variables for Python to look for the libraries in the right folder. Set the following env variables (or add them to your .bashrc)

export LDFLAGS=&quot;-L/usr/local/opt/zlib/lib&quot;
export CPPFLAGS=&quot;-I/usr/local/opt/zlib/include&quot;

The actual path for zlib might vary (its /usr/local/opt/zlib in this case. The path in your machine can be obtained by doing: brew --prefix zlib

huangapple
  • 本文由 发表于 2023年5月11日 19:45:42
  • 转载请务必保留本文链接:https://go.coder-hub.com/76227295.html
匿名

发表评论

匿名网友

:?: :razz: :sad: :evil: :!: :smile: :oops: :grin: :eek: :shock: :???: :cool: :lol: :mad: :twisted: :roll: :wink: :idea: :arrow: :neutral: :cry: :mrgreen:

确定