zoukankan      html  css  js  c++  java
  • Mac安装MySQL-python的血泪史

    现象描述

    起初正常使用pip命令提示如下的错误:

    cc -bundle -undefined dynamic_lookup -Wl,-F. build/temp.macosx-10.14-intel-2.7/_mysql.o -L/usr/local/Cellar/mysql-connector-c/6.1.11/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.14-intel-2.7/_mysql.so
      ld: library not found for -lssl
      clang: error: linker command failed with exit code 1 (use -v to see invocation)
      error: command 'cc' failed with exit status 1
      ----------------------------------------
      ERROR: Failed building wheel for mysql-python
    
    
    
    13 warnings generated.
        cc -bundle -undefined dynamic_lookup -Wl,-F. build/temp.macosx-10.14-intel-2.7/_mysql.o -L/usr/local/Cellar/mysql-connector-c/6.1.11/lib -lmysqlclient -lssl -lcrypto -o build/lib.macosx-10.14-intel-2.7/_mysql.so
        ld: library not found for -lssl
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
        error: command 'cc' failed with exit status 1
        ----------------------------------------
    ERROR: Command errored out with exit status 1: /Users/wang/.virtualenvs/flask-demo/bin/python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/T/pip-install-yqjXkS/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/T/pip-install-yqjXkS/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'
    '"'"', '"'"'
    '"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/T/pip-record-rW5Hej/install-record.txt --single-version-externally-managed --compile --install-headers /Users/wang/.virtualenvs/flask-demo/include/site/python2.7/mysql-python Check the logs for full command output.
    

    大致来看,是cc命令执行失败,没太多的思路,遂谷歌;

    尝试

    stackoverflow答案

    https://stackoverflow.com/questions/50940302/installing-mysql-python-causes-command-clang-failed-with-exit-status-1-on-mac

    参考上面的链接,执行了一下,甚至也执行了一次评论里的内容,但实际上并没啥用……

    后面甚至出现了新的问题……

    csdn答案

    https://blog.csdn.net/love_parents/article/details/80938818

    尝试了后,又提示其他的问题

    ERROR: Command errored out with exit status 1:
         command: /Users/wang/.virtualenvs/flask-demo/bin/python -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/T/pip-install-xonLuB/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/T/pip-install-xonLuB/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'
    '"'"', '"'"'
    '"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' egg_info --egg-base /private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/T/pip-install-xonLuB/mysql-python/pip-egg-info
             cwd: /private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/T/pip-install-xonLuB/mysql-python/
        Complete output (9 lines):
        Traceback (most recent call last):
          File "<string>", line 1, in <module>
          File "/private/var/folders/4r/29z_gj1n4szg9r01y5s6rxnm0000gn/T/pip-install-xonLuB/mysql-python/setup.py", line 17, in <module>
            metadata, options = get_config()
          File "setup_posix.py", line 53, in get_config
            libraries = [ dequote(i[2:]) for i in libs if i.startswith(compiler_flag("l")) ]
          File "setup_posix.py", line 8, in dequote
            if s[0] in ""'" and s[0] == s[-1]:
        IndexError: string index out of range
        ----------------------------------------
    ERROR: Command errored out with exit status 1: python setup.py egg_info Check the logs for full command output.
    

    这个问题,在此篇文章有提到,但按照他的方法并不能解决,遂继续谷歌

    最终解决办法

    https://www.cnblogs.com/LordNeo/p/9687832.html

    参考这篇文章执行了重新安装了 mysql-connector-c ,修改了mysql的配置文件;

    执行了brew info openssl,得到

    (flask-demo) ➜  homebrew-core git:(master) brew info openssl
    openssl: stable 1.0.2t (bottled) [keg-only]
    SSL/TLS cryptography library
    https://openssl.org/
    /usr/local/Cellar/openssl/1.0.2t (1,795 files, 12.0MB)
      Poured from bottle on 2019-10-30 at 18:26:15
    From: https://mirrors.tuna.tsinghua.edu.cn/git/homebrew/homebrew-core.git/Formula/openssl.rb
    ==> Caveats
    A CA file has been bootstrapped using certificates from the SystemRoots
    keychain. To add additional certificates (e.g. the certificates added in
    the System keychain), place .pem files in
      /usr/local/etc/openssl/certs
    
    and run
      /usr/local/opt/openssl/bin/c_rehash
    
    openssl is keg-only, which means it was not symlinked into /usr/local,
    because Apple has deprecated use of OpenSSL in favor of its own TLS and crypto libraries.
    
    If you need to have openssl first in your PATH run:
      echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc
    
    For compilers to find openssl you may need to set:
      export LDFLAGS="-L/usr/local/opt/openssl/lib"
      export CPPFLAGS="-I/usr/local/opt/openssl/include"
    
    For pkg-config to find openssl you may need to set:
      export PKG_CONFIG_PATH="/usr/local/opt/openssl/lib/pkgconfig"
    

    随后执行了提示里的 echo 'export PATH="/usr/local/opt/openssl/bin:$PATH"' >> ~/.zshrc

    同时,把下面语句加入了 bash_profile 并source bash_profile。

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

    再使用 pip安装,成功了……

    后记

    都2019年了,Mac/Linux安装这个包还要这么心累………………

  • 相关阅读:
    golang 创建一个简单的连接池,减少频繁的创建与关闭
    go语言string、int、int64互相转换
    JVM中的STW和CMS
    如何避免后台IO高负载造成的长时间JVM GC停顿(转)
    NetScaler VLAN’s Demystified
    NetScaler SNIPs Bound To An Interface Without A VLAN
    NetScaler Best Practice With VMAC In A High Availability Configuration
    dashboard and reporting Interface analysis
    Windows远程桌面连接 出现身份错误 要求的函数不受支持
    ns统计使用资源的SNMP OID
  • 原文地址:https://www.cnblogs.com/wswang/p/11770967.html
Copyright © 2011-2022 走看看