无法通过pip安装mysqlclient

时间:2017-02-25 02:15:32

标签: python mysql django

我正在开发一个Django(1.9.2)项目,我需要连接到MySQl数据库,我正在尝试使用推荐的mysqlclient库。但是,当我尝试通过pip install mysqlclient进行安装时,出现以下错误:

Complete output from command python setup.py egg_info:
sh: mysql_config: command not found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/private/var/folders/v9/vxdt4wms0_qgm9n10rt74p8m0000gn/T/pip-build-Xh__3p/mysqlclient/setup.py", line 17, in <module>
    metadata, options = get_config()
  File "setup_posix.py", line 44, in get_config
    libs = mysql_config("libs_r")
  File "setup_posix.py", line 26, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

我需要在哪里创建此缺失的mysql_config

1 个答案:

答案 0 :(得分:5)

对于mac:

  • brew install mysql
  • export PATH=$PATH:/usr/local/mysql/bin
  • pip install mysqlclient

它对我有用。

➜ which mysql_config    
/usr/local/bin/mysql_config

对于ubuntu:

apt-get install libmysqlclient-dev (or libmariadbclient-dev)

希望这有帮助。