pip
报错:
...
Collecting MySQL-python
Using cached MySQL-python-1.2.5.zip (108 kB)
Building wheels for collected packages: MySQL-python
Building wheel for MySQL-python (setup.py) ... error
ERROR: Command errored out with exit status 1:
command: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/l2/f66rpp1d52n1r40gfymw6lmr0000gn/T/pip-install-BO1JqY/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/l2/f66rpp1d52n1r40gfymw6lmr0000gn/T/pip-install-BO1JqY/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' bdist_wheel -d /private/var/folders/l2/f66rpp1d52n1r40gfymw6lmr0000gn/T/pip-wheel-VJXC7n
cwd: /private/var/folders/l2/f66rpp1d52n1r40gfymw6lmr0000gn/T/pip-install-BO1JqY/mysql-python/
Complete output (30 lines):
...
building '_mysql' extension
creating build/temp.macosx-11.0-x86_64-2.7
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 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/8.0.22/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-11.0-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
----------------------------------------
ERROR: Failed building wheel for MySQL-python
Running setup.py clean for MySQL-python
Failed to build MySQL-python
Installing collected packages: MySQL-python
Running setup.py install for MySQL-python ... error
ERROR: Command errored out with exit status 1:
command: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/l2/f66rpp1d52n1r40gfymw6lmr0000gn/T/pip-install-BO1JqY/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/l2/f66rpp1d52n1r40gfymw6lmr0000gn/T/pip-install-BO1JqY/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/l2/f66rpp1d52n1r40gfymw6lmr0000gn/T/pip-record-IU65zd/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /Users/answergu/Library/Python/2.7/include/python2.7/MySQL-python
cwd: /private/var/folders/l2/f66rpp1d52n1r40gfymw6lmr0000gn/T/pip-install-BO1JqY/mysql-python/
Complete output (30 lines):
...
building '_mysql' extension
creating build/temp.macosx-11.0-x86_64-2.7
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 -pipe -Dversion_info=(1,2,5,'final',1) -D__version__=1.2.5 -I/usr/local/Cellar/mysql/8.0.22/include/mysql -I/System/Library/Frameworks/Python.framework/Versions/2.7/include/python2.7 -c _mysql.c -o build/temp.macosx-11.0-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
----------------------------------------
ERROR: Command errored out with exit status 1: /System/Library/Frameworks/Python.framework/Versions/2.7/Resources/Python.app/Contents/MacOS/Python -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/l2/f66rpp1d52n1r40gfymw6lmr0000gn/T/pip-install-BO1JqY/mysql-python/setup.py'"'"'; __file__='"'"'/private/var/folders/l2/f66rpp1d52n1r40gfymw6lmr0000gn/T/pip-install-BO1JqY/mysql-python/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'rn'"'"', '"'"'n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/l2/f66rpp1d52n1r40gfymw6lmr0000gn/T/pip-record-IU65zd/install-record.txt --single-version-externally-managed --user --prefix= --compile --install-headers /Users/answergu/Library/Python/2.7/include/python2.7/MySQL-python Check the logs for full command output.
本以为是个小问题,试了网上一堆帖子,最后还是没有成功,气的我只好对以上错误日志逐字排查!
通过排查以上日志中有导入这个 /usr/local/Cellar/mysql/8.0.22/include/mysql 目录,这个目录就是我mysql的安装目录,这里边有个 mysql.h文件,我受到某个帖子的启发,执行以下命令:
cp mysql.h my_config.h
然后又执行安装
pip install mysql-python
竟然安装成功了!!!!!!
你说气人不气人!!!!!!
最后据说 mysql 8.0 之后 my_config.h 文件改名了!!!
我只能吐槽一句:大厂真是任性!