python getattr_pip install MySQL-python 被坑了两小时

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 文件改名了!!!

我只能吐槽一句:大厂真是任性!

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

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

抵扣说明:

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

余额充值