Mac下Python2.7安装MySQLdb(MySQL-pyt
Mac环境下,使用pycharm的python虚拟环境安装MySQLdb模块包遇到的问题
错误:
ImportError: No module named MySQLdb.constants
EnvironmentError: mysql_config not found
_mysql.c:44:10: fatal error: 'my_config.h' file not found
因为pycharm编辑器中直接安装会报错,所以找到对应的python虚拟环境目录(对应的项目目录/venv/bin),使用下面命令安装MySQL-python
./python -m pip install MySQL-python
报错信息:EnvironmentError: mysql_config not found
需要安装mysql依赖
brew install mysql
继续安装MySQL-python
报错信息:_mysql.c:44:10: fatal error: 'my_config.h' file not found
查询发现需要安装mysql-connector-c,使用mysql-client替代已经废弃的mysql-connector-c
brew install mysql-connector-c
下载MySQL-python安装包解压
找到/opt/homebrew/Cellar/mysql-client/8.0.29/include目录
cp mysql.h 到MySQL-python目录下 my_config.h
项目目录下的虚拟环境/venv/bin/python setup.py build
项目目录下的虚拟环境/venv/bin/python setup.py install
然后就大功告成啦~开心
image.png
最后代码还是跑不起来,因为m1芯片不支持T_T
mach-o file, but is an incompatible architecture (have 'arm64', need 'x86_64')