mac下python3.7安装mysqlclient出错解决

Posted 丹华抱一鷇音子

tags:

篇首语:本文由小常识网(cha138.com)小编为大家整理,主要介绍了mac下python3.7安装mysqlclient出错解决相关的知识,希望对你有一定的参考价值。

错误信息

Building wheel for mysqlclient (setup.py) ... error
  ERROR: Command errored out with exit status 1:
   command: /Users/dapeng/.virtualenvs/django-practice/bin/python3 -u -c ‘import sys, setuptools, tokenize; sys.argv[0] = ‘"‘"‘/private/var/folders/mq/kc_gdgd54rb08z8h4bbly5p40000gn/T/pip-install-rrwa749c/mysqlclient/setup.py‘"‘"‘; __file__=‘"‘"‘/private/var/folders/mq/kc_gdgd54rb08z8h4bbly5p40000gn/T/pip-install-rrwa749c/mysqlclient/setup.py‘"‘"‘;f=getattr(tokenize, ‘"‘"‘open‘"‘"‘, open)(__file__);code=f.read().replace(‘"‘"‘
‘"‘"‘, ‘"‘"‘
‘"‘"‘);f.close();exec(compile(code, __file__, ‘"‘"‘exec‘"‘"‘))‘ bdist_wheel -d /private/var/folders/mq/kc_gdgd54rb08z8h4bbly5p40000gn/T/pip-wheel-r79jiuyd
       cwd: /private/var/folders/mq/kc_gdgd54rb08z8h4bbly5p40000gn/T/pip-install-rrwa749c/mysqlclient/
  Complete output (30 lines):
  running bdist_wheel
  running build
  running build_py
  creating build
  creating build/lib.macosx-10.14-x86_64-3.7
  creating build/lib.macosx-10.14-x86_64-3.7/MySQLdb
  copying MySQLdb/__init__.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb
  copying MySQLdb/_exceptions.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb
  copying MySQLdb/compat.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb
  copying MySQLdb/connections.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb
  copying MySQLdb/converters.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb
  copying MySQLdb/cursors.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb
  copying MySQLdb/release.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb
  copying MySQLdb/times.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb
  creating build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/CR.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/ER.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants
  copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.14-x86_64-3.7/MySQLdb/constants
  running build_ext
  building ‘MySQLdb._mysql‘ extension
  creating build/temp.macosx-10.14-x86_64-3.7
  creating build/temp.macosx-10.14-x86_64-3.7/MySQLdb
  xcrun -sdk macosx clang -arch x86_64 -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -iwithsysroot/System/Library/Frameworks/System.framework/PrivateHeaders -iwithsysroot/Applications/Xcode.app/Contents/Developer/Library/Frameworks/Python3.framework/Versions/3.7/Headers -Dversion_info=(1,4,6,‘final‘,0) -D__version__=1.4.6 -I/usr/local/Cellar/mysql@5.7/5.7.29/include/mysql -I/Library/Developer/CommandLineTools/Library/Frameworks/Python3.framework/Versions/3.7/include/python3.7m -c MySQLdb/_mysql.c -o build/temp.macosx-10.14-x86_64-3.7/MySQLdb/_mysql.o
  xcrun -sdk macosx clang -arch x86_64 -bundle -undefined dynamic_lookup build/temp.macosx-10.14-x86_64-3.7/MySQLdb/_mysql.o -L/usr/local/Cellar/mysql@5.7/5.7.29/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.14-x86_64-3.7/MySQLdb/_mysql.cpython-37m-darwin.so
  ld: library not found for -lssl
  clang: error: linker command failed with exit code 1 (use -v to see invocation)
  error: command ‘xcrun‘ failed with exit status 1
  ----------------------------------------
  ERROR: Failed building wheel for mysqlclient

错误信息中主要有这么一条:ld: library not found for -lssl # 主要信息在这里,gcc找不到这个库

解决办法:

brew install openssl
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/    # 设置在【bash:~/.bashrc中】/【zsh:~/.zshrc中】

如果你已经安装过openssl,那么只需要在bashrc或者zshrc中配置一下LIBRARY_PATH,然后执行:source ~/.bashrc或者source ~/.zshrc
之后重新安装:pip install mysqlclient就好了。

以上是关于mac下python3.7安装mysqlclient出错解决的主要内容,如果未能解决你的问题,请参考以下文章

Mac下安装Python3.x版本

python安装教程(mac版)-python安装步骤

Mac 下安装python3.7 + pip 利用 chrome + chromedriver + selenium 自动打开网页并自动点击访问指定页面

在 Mac 上安装 Python3.6 和 Python3.7

Windows及MAC 安装Python3.7.4

text 在Mac上安装Python3.6和Python3.7