【问题标题】:error install mysqlclient with pip, library not found for -lssl使用 pip 安装 mysqlclient 时出错,找不到 -lssl 的库
【发布时间】:2019-01-13 00:36:08
【问题描述】:

我在我的 MacOS 上运行 mysql@8.x 版本,我已经用 brew 安装了 mysql 和 mysql-connector-o。目前正在与mysql brew链接。

在我的 python3 虚拟环境上运行 Django 项目我收到以下错误 -

django.core.exceptions.ImproperlyConfigured: Error loading MySQLdb module: No module named 'MySQLdb'.
Did you install mysqlclient or MySQL-python?

在使用 pip 安装 mysqlclient 时,我收到以下错误

clang -Wno-unused-result -Wsign-compare -Wunreachable-code -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -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/python/3.6.5/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 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk 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 "/Volumes/Samsung_T5/Work/python/repos/venv3/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/tmp/pip-install-kf2fkhtc/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-qwpjjw3e/install-record.txt --single-version-externally-managed --compile --install-headers /Volumes/Samsung_T5/Work/python/repos/venv3/bin/../include/site/python3.6/mysqlclient" failed with error code 1 in /private/tmp/pip-install-kf2fkhtc/mysqlclient/

【问题讨论】:

  • 您缺少 openssl 库。
  • 还要检查 the PyPi page 以了解 OsX 的任何其他先决条件和特殊说明
  • @jordanm 谢谢,在你指出的情况下,我参考了here 并得到了解决。

标签: python mysql pip


【解决方案1】:

正如jordanm 指出的那样,问题正是缺少 openssl 库,为此我按照以下步骤解决了我的问题 -

  1. 安装openssl

    brew install openssl
    
  2. 现在 pip install mysqlclient 应该可以工作。

    如果它没有并且仍然显示相同的错误library not found for -lssl,您也可以尝试链接到 brew 的 openssl:

    env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip install mysqlclient
    

    如果这仍然不起作用,您可能需要使用 pip 的 --no-cache 选项,例如

    env LDFLAGS="-I/usr/local/opt/openssl/include -L/usr/local/opt/openssl/lib" pip --no-cache install mysqlclient
    

【讨论】:

    【解决方案2】:

    通过 Homebrew 安装 openssl 后,我放置了

    export PATH="/usr/local/opt/openssl/bin:$PATH"
    export LDFLAGS="-L/usr/local/opt/openssl/lib"
    export CPPFLAGS="-I/usr/local/opt/openssl/include"
    

    在我的 .bash_profile 中运行

    source .bash_profile
    

    然后

    pip install mysqlclient
    

    【讨论】:

      猜你喜欢
      • 2014-12-04
      • 2017-03-28
      • 2021-08-18
      • 2020-01-13
      • 2019-11-24
      • 2018-12-06
      • 2020-03-12
      • 1970-01-01
      相关资源
      最近更新 更多