MacOS进行Django开发时安装mysqlclient问题解决

  1. 在直接安装mysqlclient时,会提示出错
$ pip install mysqlclient

.....
raise EnvironmentError("%s not found" % (mysql_config.path,))
  OSError: mysql_config not found
  1. 进入mysqlclient的页面说明,https://pypi.org/project/mysqlclient/,需要先,需要再Mac下先安装
# Assume you are activating Python 3 venv
$ brew install mysql
$ pip install mysqlclient

或者如果不想用server的话,就如下,建议首选这一个

# Assume you are activating Python 3 venv
$ brew install mysql-client
$ echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
$ export PATH="/usr/local/opt/mysql-client/bin:$PATH"
$ pip install mysqlclient
  1. Mac下使用brew结果也出问题了
brew install mysql
zsh: command not found: brew

那么,查找到的解决办法是

yangliu@yangs-MacBook-Pro ~ % /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
curl: (7) Failed to connect to raw.githubusercontent.com port 443 after 18 ms: Connection refused

原因是被墙了,那么,就建议用过国内Gitee镜像源了,可以解决brew的安装问题

$ /bin/bash -c "$(curl -fsSL https://gitee.com/cunkai/HomebrewCN/raw/master/Homebrew.sh)"

               开始执行Brew自动安装程序 
              [cunkai.wang@foxmail.com] 
           ['2022-06-19 16:36:12']['12.4']
        https://zhuanlan.zhihu.com/p/111014448 

不过耗时会比较久,慢慢等待即可

  1. brew install mysql-client如果出现如下问题,使用brew doctor把warning都解决掉
$ brew install mysql-client

......
fatal: not in a git directory
Error: Command failed with exit 128: git

brew doctor建议如下

$ brew doctor
Please note that these warnings are just used to help the Homebrew maintainers
with debugging if you file an issue. If everything you use Homebrew for is
working fine: please don't worry or file an issue; just ignore this. Thanks!

Warning: Homebrew/homebrew-cask was not tapped properly! Run:
  rm -rf "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask"
  brew tap homebrew/cask

Warning: Homebrew/homebrew-core was not tapped properly! Run:
  rm -rf "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-core"
  brew tap homebrew/core
(venv) yangliu@yangs-MacBook-Pro django-demo %  rm -rf "/usr/local/Homebrew/Library/Taps/homebrew/homebrew-cask"
  brew tap homebrew/cask

根据所有的建议修改一下,同样耗时很久。

最后解决以上问题就可以了

  1. 安装好之后brew install mysql-client,再运行几个命令
mysql-client is keg-only, which means it was not symlinked into /usr/local,
because it conflicts with mysql (which contains client libraries).

If you need to have mysql-client first in your PATH, run:
  echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.zshrc

For compilers to find mysql-client you may need to set:
  export LDFLAGS="-L/usr/local/opt/mysql-client/lib"
  export CPPFLAGS="-I/usr/local/opt/mysql-client/include"
  1. 最终pip install mysqlclient
  • 1
    点赞
  • 1
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值