无法在Mac OS X Mojave上安装mysqlclient

7

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

sudo pip3 install mysqlclient

I get the following error:

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/

更重要的是,看起来你没有可用的SSL库。我不使用macOS,所以我不确定如何在那里安装它们。 - Chris
@Chris 我正在使用虚拟环境。我已经安装了lssl。 - Atma
@Chris:在macOS中,默认情况下权限是这样设置的。 如果不使用sudo,则可能需要设置一个“wheel”用户才能安装东西。 - l'L'l
请避免创建错误的标签:Mac OSX在两年多前已更名为macOS。 - Cœur
6个回答

24

我在升级到mojave后遇到了与你相同的错误。经过一番搜索,以下步骤有所帮助:

brew info openssl

输出非常有用。如果您正在使用bashzsh,则该消息为:

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


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

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

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

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

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

1
brew info openssl 中的信息是关键。 - Rockallite

11

不知道它怎么做到的,但它解决了我的问题。我可以在电脑上安装mysqlclient,但在虚拟环境中却不能。那就是它了。 - Ryan Pergent
在我的Mac OS High Sierra上也能工作。 - dannydedog

4
我用以下方法解决了问题:
  1. 打开文件夹:

/Library/Developer/CommandLineTools/Packages

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

我的Mojave没有Packages文件夹,所以这对我没用。我在虚拟环境中安装了mysqlclient,然后删除了该环境以测试我的requirements文件。第二次安装库时失败了。 - stephendwolff
使用PyCharm创建虚拟环境,而不是命令行,可以得到一个干净安装mysqlclient的环境! - stephendwolff
我一直在四处寻找这个!谢谢!如果你正在使用Mojave并尝试安装mysqlclient,那么不用再找了! - Mickey Sly

1
尝试使用:-

pip install mysqlclient=1.4.2.post1


0
我在虚拟环境中运行代码"pip install mysqlclient"时遇到了一个错误。然后我运行了"pip install mysqlclient==2.1.1",它成功了。我使用的是2014款MacBook Pro,操作系统是Mac OS Mojave。

-1
你需要 virtualenv,在 Ubuntu link 上检查,同样的解决方案适用于 MacOS。

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