当我尝试运行pip install mysqlclient
时,遇到了这个问题。我已经使用brew或pip安装了所有必要的库。我尝试重新安装zlib,但似乎没有任何作用。我尝试下载brew mysql、mysql-client等,但没有任何结果。
Collecting mysqlclient
Using cached mysqlclient-2.1.1.tar.gz (88 kB)
Preparing metadata (setup.py) ... done
Building wheels for collected packages: mysqlclient
Building wheel for mysqlclient (setup.py) ... error
error: subprocess-exited-with-error
× python setup.py bdist_wheel did not run successfully.
│ exit code: 1
╰─> [43 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
running build_ext
building 'MySQLdb._mysql' 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/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 -L/opt/homebrew/opt/zlib/lib 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
[end of output]
note: This error originates from a subprocess, and is likely not a problem with pip.
ERROR: Failed building wheel for mysqlclient
Running setup.py clean for mysqlclient
Failed to build mysqlclient
ERROR: Could not build wheels for mysqlclient, which is required to install pyproject.toml-based projects
我已经尝试过:
像这样安装
$ brew install mysql
$ pip install mysqlclient
替代安装方式
$ brew install mysql-client
$ echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
$ export PATH="/usr/local/opt/mysql-client/bin:$PATH"
$ pip install mysqlclient
我看到了这个:
sudo apt-get install python3-dev default-libmysqlclient-dev build-essential
但是我有一台Mac,所以它无法解决我的问题。
/opt/homebrew/opt/zlib/lib
还是/opt/homebrew/Cellar/zlib/1.2.13/lib
?你必须使用第二个。只有路径的直接链接才能起作用。 - Richard