使用pip安装mysqlclient时出现错误,提示找不到-lssl库。

4

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

在我的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/

1
您缺少 OpenSSL 库。 - jordanm
还要查看PyPi页面,了解OsX的任何其他前提条件和特别注意事项。 - FlyingTeller
@jordanm 谢谢你,因为你指出了问题,我参考了这里并解决了它。 - Aishwary Dhare
2个回答

13

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

  1. 安装openssl

brew install openssl
现在 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

0

通过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

网页内容由stack overflow 提供, 点击上面的
可以查看英文原文,
原文链接