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
主要的报错有两点:
- my_config.h not found
- mysql_config not found
解决办法
- 首先确保brew安装正确
- 先卸载mysql mysql-python等
brew uninstall mysql
brew uninstall mysql-client
brew uninstall mysql-connector-c++
- 安装mysql
brew install mysql
brew link mysql
如果brew link mysql
失败,报错Error: Could not symlink bin/mysql_config
执行
brew link --overwrite mysql
- 单独下载
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/
- 安装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
即可