The history of MySQL Python installation on Mac

Phenomenal description

At first, the pip command prompts the following errors:

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('"'"'\r\n'"'"', '"'"'\n'"'"');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.

Generally speaking, cc command failed to execute, and there was not much thinking, so Google;

attempt

stackoverflow answer

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

Refer to the above link, execute it for a while, and even execute the content in the comment, but it's not really useful...

There are even new problems...

csdn answer

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

After trying, I will prompt other questions.

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('"'"'\r\n'"'"', '"'"'\n'"'"');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.

This problem, mentioned in this article, can not be solved according to his method, so continue to Google.

Final solution

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

Refer to this article to reinstall mysql-connector-c and modify the MySQL configuration file.

Execute brew info openssl and get

(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"

Then I execute echo 'export path = "/ usr / local / opt / OpenSSL / bin: $path"' > ~ /. Zshrc in the prompt.

At the same time, add the following statement to bash profile and source bash profile.

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

Use pip again to install, and it is successful...

Epilogue

It's 2019. I'm so tired to install this package on Mac/Linux...

Keywords: Python OpenSSL MySQL pip

Added by kiss the robot on Fri, 01 Nov 2019 08:43:06 +0200