Error installing mysql-python/mysqlclient: library not found for -lssl

macOS Mojave 安装mysqlclient时提示没有ssl库,错误如下:

Installing collected packages: mysqlclient
  Running setup.py install for mysqlclient ... error
    Complete output from command /Users/moon/Workspace/Pycharm/env-tonghang/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/6z/3d8pkqg53r72hd3gvt71n0900000gn/T/pip-install-dk68k229/mysqlclient/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/6z/3d8pkqg53r72hd3gvt71n0900000gn/T/pip-record-4eo9tbll/install-record.txt --single-version-externally-managed --compile --install-headers /Users/moon/Workspace/Pycharm/env-tonghang/include/site/python3.6/mysqlclient:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.13-x86_64-3.6
    copying _mysql_exceptions.py -> build/lib.macosx-10.13-x86_64-3.6
    creating build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/compat.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    creating build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.13-x86_64-3.6
    clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 -I/usr/local/opt/mysql@5.7/include/mysql -I/Users/moon/Workspace/Pycharm/env-tonghang/include -I/usr/local/Cellar/python/3.6.5_1/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c _mysql.c -o build/temp.macosx-10.13-x86_64-3.6/_mysql.o
    clang -bundle -undefined dynamic_lookup build/temp.macosx-10.13-x86_64-3.6/_mysql.o -L/usr/local/opt/mysql@5.7/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.13-x86_64-3.6/_mysql.cpython-36m-darwin.so
    ld: library not found for -lssl
    clang: error: linker command failed with exit code 1 (use -v to see invocation)
    error: command 'clang' failed with exit status 1
    
    ----------------------------------------
Command "/Users/moon/Workspace/Pycharm/env-tonghang/bin/python -u -c "import setuptools, tokenize;__file__='/private/var/folders/6z/3d8pkqg53r72hd3gvt71n0900000gn/T/pip-install-dk68k229/mysqlclient/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/6z/3d8pkqg53r72hd3gvt71n0900000gn/T/pip-record-4eo9tbll/install-record.txt --single-version-externally-managed --compile --install-headers /Users/moon/Workspace/Pycharm/env-tonghang/include/site/python3.6/mysqlclient" failed with error code 1 in /private/var/folders/6z/3d8pkqg53r72hd3gvt71n0900000gn/T/pip-install-dk68k229/mysqlclient/

Screen Shot 2019-06-19 at 14.06.27.png

解决方法可以指定ssl库

LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient

或在~/.bash_*中指定环境

export LDFLAGS="-L/usr/local/opt/openssl/lib"

To StackoverflowError installing mysql-python: library not found for -lssl

Tag: none

Leave a new comment