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(‘"‘"‘\r\n‘"‘"‘, ‘"‘"‘\n‘"‘"‘);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出错解决

上一篇:MySQL巡检


下一篇:Oracle统计一个小时内,一天内、一个星期内、一个月内、一年内的数据