我正在尝试在 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/
升级到 mojave 后,我遇到了与您相同的错误。经过一番挖掘后,以下步骤会有所帮助:
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"
export LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/
来自 ld:Mac OS Sierra 升级后找不到 -lssl 的库
它对我有用。
我通过以下方法解决了这个问题:
/库/开发人员/CommandLineTools/Packages
pip3 install mysqlclient
尝试使用:-
pip install mysqlclient=1.4.2.post1
当我在 virtualenv 中运行代码“pip install mysqlclient”时出现错误。然后我运行“pip install mysqlclient==2.1.1”并且它起作用了。我在 2014 年 MacBook Pro 上使用 mac OS Mojave。
您需要 virtualenv,请查看此 Ubuntu 链接,相同的解决方案适用于 MacOS