macbook如何安装mysql-python踩坑记录

macbook如何安装mysql-python踩坑记录

安装mysql-python

以下是报错信息:

  cc -fno-strict-aliasing -fno-common -dynamic -g -Os -pipe -fno-common -fno-strict-aliasing -fwrapv -DENABLE_DTRACE -DMACOSX -DNDEBUG -Wall -Wstrict-prototypes -Wshorten-64-to-32 -iwithsysroot /usr/local/libressl/include -DNDEBUG -g -fwrapv -Os -Wall -Wstrict-prototypes -DENABLE_DTRACE -arch x86_64 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/opt/mysql-client/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-10.15-x86_64-2.7/_mysql.o
  _mysql.c:44:10: fatal error: 'my_config.h' file not found
  #include "my_config.h"
           ^~~~~~~~~~~~~
  1 error generated.
  error: command 'cc' failed with exit status 1

主要的报错有两点:

  1. my_config.h not found
  2. mysql_config not found

解决办法

  1. 首先确保brew安装正确
  2. 先卸载mysql mysql-python等
brew uninstall mysql
brew uninstall mysql-client
brew uninstall mysql-connector-c++
  1. 安装mysql
brew install mysql
brew link mysql 

如果brew link mysql 失败,报错Error: Could not symlink bin/mysql_config
执行

brew link --overwrite mysql
  1. 单独下载my_config.h
wget https://raw.githubusercontent.com/jacobjohn2016/MySQL-Medium/main/my_config.h

如果没有wget, 执行brew install wget即可
5. 移动my_config.h 到mysql include目录下

mv my_config.h /usr/local/Cellar/mysql/8.0.23/include/mysql/
  1. 安装mysql-python
pip install MySQL-python

如果报错:

   cc -bundle -undefined dynamic_lookup -Wl,-F. -L/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/libressl/lib build/temp.macosx-10.15-x86_64-2.7/_mysql.o -L/usr/local/Cellar/mysql/8.0.23/lib -lmysqlclient -lssl -lcrypto -lresolv -o build/lib.macosx-10.15-x86_64-2.7/_mysql.so
    ld: warning: directory not found for option '-L/BuildRoot/Applications/Xcode.app/Contents/Developer/Platforms/MacOSX.platform/Developer/SDKs/MacOSX10.15.Internal.sdk/usr/local/libressl/lib'
    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

那是因为没有安装openssl等,执行

brew install pkg-config libffi openssl
brew link openssl --force

再次执行pip install mysql-python 即可

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值