无法在Mac OS X Mojave上安装mysqlclient

时间:2018-11-02 00:14:32

标签: python macos mysql-python mysql-connector macos-mojave

我正在尝试在Mac OS X Mojave上安装mysqlclient:

sudo pip3 install mysqlclient

我收到以下错误:

clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -I/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk/System/Library/Frameworks/Tk.framework/Versions/8.5/Headers -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 -I/usr/local/Cellar/mysql/8.0.12/include/mysql -I/usr/local/Cellar/python3/3.6.4/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/Cellar/mysql/8.0.12/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//Development/apps/hid_ve/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-1mo7e_ok/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/tmp/pip-record-9bwluwz6/install-record.txt --single-version-externally-managed --compile --install-headers /Users//Development/apps/hid_ve/bin/../include/site/python3.6/mysqlclient" failed with error code 1 in /private/tmp/pip-install-1mo7e_ok/mysqlclient/

5 个答案:

答案 0 :(得分:5)

升级到莫哈韦沙漠后,我遇到了与您相同的错误。经过一番挖掘之后,以下步骤会有所帮助:

brew info openssl

输出很有用。如果您使用的是 bash zsh ,则消息为:

要让编译器找到openssl,您可能需要设置:

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

执行上述命令后,一切恢复正常。

此外,如果您使用的是。消息是:

要让编译器找到openssl,您可能需要设置:

set -gx LDFLAGS "-L/usr/local/opt/openssl/lib"
set -gx CPPFLAGS "-I/usr/local/opt/openssl/include"

答案 1 :(得分:5)

export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/

来自ld: library not found for -lssl after Mac OS Sierra upgrade

对我有用。

答案 2 :(得分:3)

我通过以下方法解决了这个问题:

  1. 转到文件夹:
  

/ Library / Developer / CommandLineTools / Packages

  1. 单击并安装:macOS_SDK_headers_for_macOS_10.14.pkg
  2. 删除虚拟环境
  3. 创建一个新的虚拟环境。
  4. 安装mysqlclient:pip3 install mysqlclient

答案 3 :(得分:0)

尝试使用:-

pip install mysqlclient = 1.4.2.post1

答案 4 :(得分:-2)

您需要virtualenv,签出此Ubuntu link,相同的解决方案适用于MacOS