当前位置:首页 » Mysql技术教程

Mac 安装mysqlclient报错,OSError: mysql_config not found 的解决方法

2018-06-19 08:21 本站整理 浏览(10)

Complete output from command python setup.py egg_info:

/bin/sh: mysql_config: command not found

Traceback (most recent call last):

  File "<string>", line 1, in <module>

  File "/private/var/folders/ww/hnzjh2z517d72m15ybyhwkbw0000gn/T/pip-build-mvq09hkr/mysqlclient/setup.py", line 17, in <module>

    metadata, options = get_config()

  File "/private/var/folders/ww/hnzjh2z517d72m15ybyhwkbw0000gn/T/pip-build-mvq09hkr/mysqlclient/setup_posix.py", line 44, in get_config

    libs = mysql_config("libs_r")

  File "/private/var/folders/ww/hnzjh2z517d72m15ybyhwkbw0000gn/T/pip-build-mvq09hkr/mysqlclient/setup_posix.py", line 26, in mysql_config

    raise EnvironmentError("%s not found" % (mysql_config.path,))

OSError: mysql_config not found

 

解决办法:

安装mysql-connector-c:

brew install mysql-connector-c

 如果电脑没有安装brew,按照以下方式安装brew,再安装mysql-connector-c:

 

 

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

 

 

再次安装mysqlclient:

pip install mysqlclient

 

 

发现报了一个新的错误:

Collecting mysqlclient

  Using cached mysqlclient-1.3.10.tar.gz

    Complete output from command python setup.py egg_info:

    Traceback (most recent call last):

      File "<string>", line 1, in <module>

      File "/private/var/folders/rv/a_a/T/pip-build-nyaa8t95/mysqlclient/setup.py", line 17, in <module>

        metadata, options = get_config()

      File "/private/var/folders/rv/a_a/T/pip-build-nyaa8t95/mysqlclient/setup_posix.py", line 54, in get_config

        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]

      File "/private/var/folders/rv/a_a/T/pip-build-nyaa8t95/mysqlclient/setup_posix.py", line 54, in <listcomp>

        libraries = [dequote(i[2:]) for i in libs if i.startswith('-l')]

      File "/private/var/folders/rv/a_a/T/pip-build-nyaa8t95/mysqlclient/setup_posix.py", line 12, in dequote

        if s[0] in "\"'" and s[0] == s[-1]:

 

    IndexError: string index out of range

 

 

解决办法:修改mysql-config文件:

cd /usr/local/Cellar/mysql-connector-c/6.1.11/bin/
# 备份
cp  mysql_config mysql_config.bak   
chmod u+w mysql_config
vi mysql_config

#   :114    找到第114行
# 将
#  libs="$libs -l "
# 替换为
#  libs="$libs -lmysqlclient -lssl -lcrypto"
#保存

 

再次安装mysqlclient:

 

pip install mysqlclient

 

成功!