Mac安装MySQL-python的血泪史
程序员文章站
2023-08-30 14:14:31
现象描述 起初正常使用pip命令提示如下的错误: cc bundle undefined dynamic_lookup Wl, F. build/temp.macosx 10.14 intel 2.7/_mysql.o L/usr/local/Cellar/mysql connector c/6.1 ......
现象描述
起初正常使用pip命令提示如下的错误:
cc -bundle -undefined dynamic_lookup -wl,-f. build/temp.macosx-10.14-intel-2.7/_mysql.o -l/usr/local/cellar/mysql-connector-c/6.1.11/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.14-intel-2.7/_mysql.so ld: library not found for -lssl clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command 'cc' failed with exit status 1 ---------------------------------------- error: failed building wheel for mysql-python 13 warnings generated. cc -bundle -undefined dynamic_lookup -wl,-f. build/temp.macosx-10.14-intel-2.7/_mysql.o -l/usr/local/cellar/mysql-connector-c/6.1.11/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.14-intel-2.7/_mysql.so ld: library not found for -lssl clang: error: linker command failed with exit code 1 (use -v to see invocation) error: command 'cc' failed with exit status 1 ---------------------------------------- error: command errored out with exit status 1: /users/wang/.virtualenvs/flask-demo/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/t/pip-install-yqjxks/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/t/pip-install-yqjxks/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/t/pip-record-rw5hej/install-record.txt --single-version-externally-managed --compile --install-headers /users/wang/.virtualenvs/flask-demo/include/site/python2.7/mysql-python check the logs for full command output.
大致来看,是cc命令执行失败,没太多的思路,遂谷歌;
尝试
*答案
参考上面的链接,执行了一下,甚至也执行了一次评论里的内容,但实际上并没啥用……
后面甚至出现了新的问题……
csdn答案
尝试了后,又提示其他的问题
error: command errored out with exit status 1: command: /users/wang/.virtualenvs/flask-demo/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/t/pip-install-xonlub/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/t/pip-install-xonlub/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/t/pip-install-xonlub/mysql-python/pip-egg-info cwd: /private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/t/pip-install-xonlub/mysql-python/ complete output (9 lines): traceback (most recent call last): file "<string>", line 1, in <module> file "/private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/t/pip-install-xonlub/mysql-python/setup.py", line 17, in <module> metadata, options = get_config() file "setup_posix.py", line 53, in get_config libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ] file "setup_posix.py", line 8, in dequote if s[0] in "\"'" and s[0] == s[-1]: indexerror: string index out of range ---------------------------------------- error: command errored out with exit status 1: python setup.py egg_info check the logs for full command output.
这个问题,在此篇文章有提到,但按照他的方法并不能解决,遂继续谷歌
最终解决办法
https://www.cnblogs.com/lordneo/p/9687832.html
参考这篇文章执行了重新安装了 mysql-connector-c ,修改了mysql的配置文件;
执行了brew info openssl,得到
(flask-demo) ➜ homebrew-core git:(master) brew info openssl openssl: stable 1.0.2t (bottled) [keg-only] ssl/tls cryptography library https://openssl.org/ /usr/local/cellar/openssl/1.0.2t (1,795 files, 12.0mb) poured from bottle on 2019-10-30 at 18:26:15 from: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git/formula/openssl.rb ==> caveats a ca file has been bootstrapped using certificates from the systemroots keychain. to add additional certificates (e.g. the certificates added in the system keychain), place .pem files in /usr/local/etc/openssl/certs and run /usr/local/opt/openssl/bin/c_rehash openssl is keg-only, which means it was not symlinked into /usr/local, because apple has deprecated use of openssl in favor of its own tls and crypto libraries. if you need to have openssl first in your path run: echo 'export path="/usr/local/opt/openssl/bin:$path"' >> ~/.zshrc for compilers to find openssl you may need to set: export ldflags="-l/usr/local/opt/openssl/lib" export cppflags="-i/usr/local/opt/openssl/include" for pkg-config to find openssl you may need to set: export pkg_config_path="/usr/local/opt/openssl/lib/pkgconfig"
随后执行了提示里的 echo 'export path="/usr/local/opt/openssl/bin:$path"' >> ~/.zshrc
同时,把下面语句加入了 bash_profile 并source bash_profile。
export ldflags="-l/usr/local/opt/openssl/lib" export cppflags="-i/usr/local/opt/openssl/include"
再使用 pip安装,成功了……
后记
都2019年了,mac/linux安装这个包还要这么心累………………
上一篇: Ubuntu java环境变量配置
下一篇: 文字溢出省略