因为新项目要引用MySQLdb,而且是python2,之前自己写机器学习的项目都是python3,搞了一个早上,卡在import MySQLdb上了
运行
pip2 install mysqlclient告诉我
dflags=''
File "<string>", line 1, in <module>
File "/private/var/folders/l3/hc2gmq15269bw3j7258p2tgc0000gn/T/pip-install-9KeT9n/mysqlclient/setup.py", line 16, in <module>
metadata, options = get_config()
File "setup_posix.py", line 51, in get_config
libs = mysql_config("libs")
File "setup_posix.py", line 29, in mysql_config
raise EnvironmentError("%s not found" % (_mysql_config_path,))
EnvironmentError: mysql_config not found
----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /private/var/folders/l3/hc2gmq15269bw3j7258p2tgc0000gn/T/pip-install-9KeT9n/mysqlclient/试了好多办法
终于在
stackoverflow.com/questions/5…
找到了完美解决方案
I just resolved this exact issue when running Ansible's mysql_user module. The answer here helped tip me off to a solution. I also neededMySQL-pythonfrompip, which also broke in this process, so I've added the extra steps.Steps to resolve:
brew unlink mysql # only if installed, causes the next step to failbrew install mysql-connector-c- locate
mysql_configfile withwhich (mysql_config)edit the
mysql_configfile, under# Create optionschange this:
libs="$libs -l "to this:
libs="$libs -lmysqlclient -lssl -lcrypto"if using vim,
:wq!to save the read-only fileNow the install should run successfully
pip install mysqlclientAdding this separately, as it's similar but not directly related to the initial question
pip install MySQL-pythonFix
mysqlbrew formula, if it was unlinked in the first step.
brew unlink mysql-connector-c
brew link mysql
感觉有点坑啊