【问题标题】:OSX ld: library not found for -lsslOSX ld:找不到 -lssl 的库
【发布时间】:2018-08-08 02:22:17
【问题描述】:

我正在尝试使用 python 3 在 OSX high sierra 上的 virtrualenv 中安装 mysqlclient。得到以下错误:

  Failed building wheel for mysqlclient
  Running setup.py clean for mysqlclient
Failed to build mysqlclient
Installing collected packages: mysqlclient, coverage, django-coverage-plugin, Pygments, babel, alabaster, sphinxcontrib-websupport, imagesize, pyparsing, packaging, snowballstemmer, MarkupSafe, Jinja2, docutils, Sphinx, typing, django-extensions, Werkzeug, django-test-plus, text-unidecode, python-dateutil, Faker, factory-boy, sqlparse, django-debug-toolbar, decorator, simplegeneric, wcwidth, prompt-toolkit, appnope, pickleshare, ptyprocess, pexpect, ipython-genutils, traitlets, parso, jedi, ipython, ipdb, py, pluggy, attrs, pytest, pytest-django, termcolor, pytest-sugar
  Running setup.py install for mysqlclient ... error
    Complete output from command /private/var/virtualenvs/todobackend/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/80/lb0c7r0s5bj3rfrvv1pp85g80000gn/T/pip-build-sqswyq3d/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 /var/folders/80/lb0c7r0s5bj3rfrvv1pp85g80000gn/T/pip-g8z3z8q5-record/install-record.txt --single-version-externally-managed --compile --install-headers /private/var/virtualenvs/todobackend/bin/../include/site/python3.6/mysqlclient:
    running install
    running build
    running build_py
    creating build
    creating build/lib.macosx-10.13-x86_64-3.6
    copying _mysql_exceptions.py -> build/lib.macosx-10.13-x86_64-3.6
    creating build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/__init__.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/compat.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/connections.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/converters.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/cursors.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/release.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    copying MySQLdb/times.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb
    creating build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/__init__.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/CLIENT.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/CR.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/ER.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/FIELD_TYPE.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/FLAG.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    copying MySQLdb/constants/REFRESH.py -> build/lib.macosx-10.13-x86_64-3.6/MySQLdb/constants
    running build_ext
    building '_mysql' extension
    creating build/temp.macosx-10.13-x86_64-3.6
    clang -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -Qunused-arguments -Qunused-arguments -Dversion_info=(1,3,12,'final',0) -D__version__=1.3.12 -I/usr/local/Cellar/mysql/5.7.10/include/mysql -I/usr/local/Cellar/python3/3.6.4_2/Frameworks/Python.framework/Versions/3.6/include/python3.6m -c _mysql.c -o build/temp.macosx-10.13-x86_64-3.6/_mysql.o -fno-omit-frame-pointer
    In file included from _mysql.c:29:
    In file included from /usr/local/Cellar/mysql/5.7.10/include/mysql/mysql.h:64:
    /usr/local/Cellar/mysql/5.7.10/include/mysql/mysql/client_plugin.h:97:3: warning: this function declaration is not a prototype [-Wstrict-prototypes]
      MYSQL_CLIENT_PLUGIN_HEADER
      ^
    /usr/local/Cellar/mysql/5.7.10/include/mysql/mysql/client_plugin.h:92:16: note: expanded from macro 'MYSQL_CLIENT_PLUGIN_HEADER'
      int (*deinit)();                                      \
                   ^
    /usr/local/Cellar/mysql/5.7.10/include/mysql/mysql/client_plugin.h:107:3: warning: this function declaration is not a prototype [-Wstrict-prototypes]
      MYSQL_CLIENT_PLUGIN_HEADER
      ^
    /usr/local/Cellar/mysql/5.7.10/include/mysql/mysql/client_plugin.h:92:16: note: expanded from macro 'MYSQL_CLIENT_PLUGIN_HEADER'
      int (*deinit)();                                      \
                   ^
    2 warnings generated.
    clang -bundle -undefined dynamic_lookup -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.13.sdk -Qunused-arguments -Qunused-arguments build/temp.macosx-10.13-x86_64-3.6/_mysql.o -L/usr/local/Cellar/mysql/5.7.10/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 "/private/var/virtualenvs/todobackend/bin/python3.6 -u -c "import setuptools, tokenize;__file__='/private/var/folders/80/lb0c7r0s5bj3rfrvv1pp85g80000gn/T/pip-build-sqswyq3d/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 /var/folders/80/lb0c7r0s5bj3rfrvv1pp85g80000gn/T/pip-g8z3z8q5-record/install-record.txt --single-version-externally-managed --compile --install-headers /private/var/virtualenvs/todobackend/bin/../include/site/python3.6/mysqlclient" failed with error code 1 in /private/var/folders/80/lb0c7r0s5bj3rfrvv1pp85g80000gn/T/pip-build-sqswyq3d/mysqlclient/

尝试了xcode-select --install,但没有成功。而且我已经在同一台电脑上安装了mysql服务器。

【问题讨论】:

    标签: mysql python-3.x macos virtualenv


    【解决方案1】:

    感谢radtek's answer,我只用这个命令就解决了:

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

    让它也适用于未来的终端会话:

    echo 'export LDFLAGS="-L/usr/local/opt/openssl/lib"' >> ~/.zshrc
    

    【讨论】:

      【解决方案2】:

      如果你有 openssl@1.1,你会遇到错误,因为 mysqlclient 使用 /usr/local/opt/openssl 而它不在你的目录中。因此,创建一个名称为openssl 的符号链接指向openssl@1.1

      这个 shell 命令对我有用 -

      ln -s /usr/local/opt/openssl@1.1 /usr/local/opt/openssl
      

      【讨论】:

        【解决方案3】:

        升级到 osx Mojave 和 python 3.7.2 后,我遇到了同样的问题。这对我有用:

        # Required for mysqlclient, see brew info openssl
        echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.bash_profile
        export LDFLAGS="-L/usr/local/opt/openssl/lib"
        export CPPFLAGS="-I/usr/local/opt/openssl/include"
        
        pip3 install mysqlclient
        

        希望对您有所帮助。更多信息请见here

        【讨论】:

        • 我遇到了同样的错误,这些命令在我的本地修复了它,但是当我尝试部署到 heroku 时,我得到了同样的错误,知道如何解决这个问题吗?
        • 您可能需要在您的实例上安装 openssl。我实际上对heroku并不熟悉。我意识到与我使用的 AWS ec2 实例相比,您对服务器的控制较少。
        猜你喜欢
        • 2017-08-08
        • 2019-11-24
        • 1970-01-01
        • 2022-09-23
        • 2019-06-11
        • 1970-01-01
        • 2020-04-21
        • 2018-02-08
        • 1970-01-01
        相关资源
        最近更新 更多