[筆記]Python3 MySQLdb問題

最近在GCP開了一台CentOS打算在上面run些東西,打算做些資料庫串接之類的

pip3 install mysqlclient

結果就噴了下面的錯誤了呢。

_mysql.c:40:20: fatal error: Python.h: No such file or directory
#include "Python.h"
^
compilation terminated.
error: command 'x86_64-linux-gnu-gcc' failed with exit status 1

查了一下是因為python沒有安裝dev版本,原本想說跟ubuntu一樣sudo apt-get install python3-dev結果什麼都沒找到

於是試了一下以下指令找到了~

➜ ~ yum search python3 | grep devel
python34-cairo-devel.x86_64 : Libraries and headers for python34-cairo
python34-greenlet-devel.x86_64 : C development headers for python34-greenlet
python34-devel.x86_64 : Libraries and header files needed for Python 3
: development
python34u-devel.x86_64 : Libraries and header files needed for Python 3
: development
python35u-devel.x86_64 : Libraries and header files needed for Python 3
: development
python36u-devel.x86_64 : Libraries and header files needed for Python
: development

看好自己常用的python版本裝下去就好囉。
sudo yum install python35u-devel.x86_64

補充

如果上述還是不能的話需要另外安裝 libmysqlclient-dev