最开始我用的是官网下载的mysql.connector,不太好用,新手还是跟着大众走比较好。
坑1:
import MySQLdb
显示`no module named ‘MySQLdb’
pip install MySQLdb
随之而来的就是各种错误,搜一下,对于各个平台都有替代安装方法,但大家都没写Mac的解决方案,但经尝试,pip install mysqlclient
是可以的,装好之后也同样可以使用MySQLdb,具体安装方法:
BEEFdeMacBook-Pro:FreeBasic beef$ brew install mysql-client
BEEFdeMacBook-Pro:FreeBasic beef$ echo 'export PATH="/usr/local/opt/mysql-client/bin:$PATH"' >> ~/.bash_profile
BEEFdeMacBook-Pro:FreeBasic beef$ export PATH="/usr/local/opt/mysql-client/bin:$PATH"
BEEFdeMacBook-Pro:FreeBasic beef$ pip install mysqlclient
此时import MySQLdb不再显示 no module
坑2:
安装好了,运行程序,报错:
ImportError: dlopen(。。。/MySQLdb/_mysql.cpython-37m-darwin.so, 2): Library not loaded: @