这是我得到的错误

(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
  Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
  Running setup.py egg_info for package mysql-python
    sh: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 24, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    Complete output from command python setup.py egg_info:
    sh: mysql_config: not found

Traceback (most recent call last):

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

  File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>

    metadata, options = get_config()

  File "setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "setup_posix.py", line 24, 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
Storing complete log in /home/zjm1126/.pip/pip.log
(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
  Running setup.py egg_info for package mysql-python
    sh: mysql_config: not found
    Traceback (most recent call last):
      File "<string>", line 14, in <module>
      File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
        metadata, options = get_config()
      File "setup_posix.py", line 43, in get_config
        libs = mysql_config("libs_r")
      File "setup_posix.py", line 24, in mysql_config
        raise EnvironmentError("%s not found" % (mysql_config.path,))
    EnvironmentError: mysql_config not found
    Complete output from command python setup.py egg_info:
    sh: mysql_config: not found

Traceback (most recent call last):

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

  File "/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>

    metadata, options = get_config()

  File "setup_posix.py", line 43, in get_config

    libs = mysql_config("libs_r")

  File "setup_posix.py", line 24, 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
Storing complete log in /home/zjm1126/.pip/pip.log

我能做些什么来解决这个问题?


当前回答

我在《Terraform》中也遇到了同样的问题:光容器。它基于Alpine。

你必须安装mariadb-dev:

apk add mariadb-dev

但这是不够的,因为所有其他依赖项都被遗漏了:

apk add python2 py2-pip gcc python2-dev musl-dev

其他回答

在Mac:

brew install mysql-client

定位mysql

mdfind mysql | grep bin

然后添加到路径

export PATH=$PATH:/usr/local/Cellar/mysql-client/8.0.23/bin/

或永久

echo "export PATH=$PATH:/usr/local/Cellar/mysql-client/8.0.23/bin/" >> ~/.zshrc
source ~/.zshrc

似乎mysql_config在您的系统中丢失或安装程序无法找到它。 确保mysql_config真的安装了。

例如,在Debian/Ubuntu上,你必须安装这个包:

sudo apt-get install libmysqlclient-dev

也许mysql_config不在你的路径中,当你自己编译时就会出现这种情况 mysql套件。

更新:对于debian/ubuntu的最新版本(截至2018年)

sudo apt install default-libmysqlclient-dev

试试sudo apt-get build-dep python-mysqldb

你可以使用MySQL连接器/Python

通过PyPip安装

pip install mysql-connector-python

更多信息可以在MySQL Connector/Python 1.0.5 beta公告博客上找到。

在Launchpad上有一个很好的例子,说明如何使用库添加、编辑或删除数据。

在Mac OS中,我只是在终端中运行这个来修复:

export PATH=$PATH:/usr/local/mysql/bin

这是我找到的最快的修复方法-它将它添加到路径中,但我认为如果你计划在另一个环境中安装MySQL-python,最好将它永久添加(即添加到/etc/paths)。

(在OSX Mountain Lion中测试)