macOS pip3 install mysqlclient 报错

浪费了一晚上时间解决了,记录一下希望有相同问题的朋友不会再因为这个问题浪费大量时间


  • 问题一
    OSError: mysql_config not found
    我的机器只安装了mysql客户端,没有安装服务端,安装后解决.

    1. 安装homebrew
      /usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
    2. 安装mysql
      brew install mysql
  • 问题二
    xcrun: error: invalid active developer path (/Library/Developer/CommandLineTools), missing xcrun
    重装command line tools工具就好了

    1. 执行xcode安装
      xcode-select –install
    2. 期间如果提示安装失败
      xcode-select: error: command line tools are already installed, use "Software Update" to install updates
    3. 需要执行
      sudo rm -rf /Library/Developer/CommandLineTools
    4. 然后再次执行
      xcode-select –install
  • 问题三
    ld: library not found for -lssl
    这个问题最头疼,查了好久没有解决方案,最后在shenguanjiejie的文章里找到了解决方法,感谢!
    显式设置ssl库路径解决问题!
    LDFLAGS=-L/usr/local/opt/openssl/lib pip install mysqlclient

(venv) ➜  datamanager LDFLAGS=-L/usr/local/opt/openssl/lib pip3 install mysqlclient
Collecting mysqlclient
  Using cached https://files.pythonhosted.org/packages/d0/97/7326248ac8d5049968bf4ec708a5d3d4806e412a42e74160d7f266a3e03a/mysqlclient-1.4.6.tar.gz
Installing collected packages: mysqlclient
    Running setup.py install for mysqlclient ... done
Successfully installed mysqlclient-1.4.6
(venv) ➜  datamanager

参考链接:
https://stackoverflow.com/questions/34617452/how-to-update-xcode-from-command-line
https://github.com/PyMySQL/mysqlclient-python/issues/131

你可能感兴趣的:(macOS pip3 install mysqlclient 报错)