今天无意间把MySQL升级到了8.0.22_1,然后pip安装mysqlclient发现会报以下错误:
/usr/bin/clang -fno-strict-aliasing -Wsign-compare -fno-common -dynamic -DNDEBUG -g -fwrapv -O3 -Wall -Wstrict-prototypes -arch i386 -arch x86_64 -g -Dversion_info=(1,3,13,'final',0) -D__version__=1.3.13 -I/usr/local/Cellar/mysql-connector-c/6.1.11/include -I/Library/Frameworks/Python.framework/Versions/3.5/include/python3.5m -c _mysql.c -o build/temp.macosx-10.6-intel-3.5/_mysql.o _mysql.c:29:10: fatal error: 'mysql.h' file not found #include "mysql.h" ^~~~~~~~~ 1 error generated. error: command '/usr/bin/clang' failed with exit status 1 ---------------------------------------- ERROR: Command errored out with exit status 1: /Users/wangxvyang/Desktop/lls/saas_venv/bin/python3.5 -u -c 'import sys, setuptools, tokenize; sys.argv[0] = '"'"'/private/var/folders/07/v8slhf9x5zsbbd8_9cd5ztnh0000gp/T/pip-install-0hr2meqk/mysqlclient_8acf18de89944ee2ad989cb2f8835068/setup.py'"'"'; __file__='"'"'/private/var/folders/07/v8slhf9x5zsbbd8_9cd5ztnh0000gp/T/pip-install-0hr2meqk/mysqlclient_8acf18de89944ee2ad989cb2f8835068/setup.py'"'"';f=getattr(tokenize, '"'"'open'"'"', open)(__file__);code=f.read().replace('"'"'\r\n'"'"', '"'"'\n'"'"');f.close();exec(compile(code, __file__, '"'"'exec'"'"'))' install --record /private/var/folders/07/v8slhf9x5zsbbd8_9cd5ztnh0000gp/T/pip-record-5qvzp9ru/install-record.txt --single-version-externally-managed --compile --install-headers /Users/wangxvyang/Desktop/lls/saas_venv/include/site/python3.5/mysqlclient Check the logs for full command output.
- 大概意思就是找不到mysql.h这个文件了。
根据报错内容查了一下
/usr/local/Cellar/mysql-connector-c/6.1.11/include
这个文件夹发现,文件夹就不存在,根据路径可以看出来这个查找的版本还是6.1.11
,到/usr/local/Cellar/mysql-connector-c/
文件夹看了一下,发现里面只有一个8.0.22_1
的文件夹,刚好8.0.22_1
里面有mysql.h
这个文件,突发奇想,能不能复制一个改名为6.1.11
,说干就干:cd /usr/local/Cellar/mysql-connector-c/ cp -r 8.0.22_1 6.1.11
重试了一下,发现依然找不到
mysql.h
,仔细看了一下路径,发现/usr/local/Cellar/mysql-connector-c/6.1.11/include
下多了一层mysql
的文件夹,把mysql
文件夹里的数据文件全部提到/usr/local/Cellar/mysql-connector-c/6.1.11/include
这一层。cd 6.1.11/include cp -r mysql/* ../include/
- 然后重新
pip install mysqlclient
,竟然搞定了!!! - ps:这个方法明显不是最优方案,但是查了好久资料也没有找到能够直接调整pip install时获取mysql.h路径的方法,只能先用这个了,如果有知道更好方法的希望能够分享出来,多谢!