这是我得到的错误

(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

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


当前回答

有时错误取决于实际原因。我们有一个通过python-mysqldb debian包安装mysql-python的案例。

一个不知道这一点的开发人员,不小心运行了PIP卸载mysql-python,然后无法恢复PIP安装mysql-python,给出了上述错误。

PIP卸载mysql-python已经破坏了debian包的内容,当然PIP安装mysql-python失败了,因为debian包不需要任何dev文件。

在这种情况下,正确的解决方案是apt-get install—重新安装python-mysqldb,将mysql-python恢复到原始状态。

其他回答

在MacOS Mojave上,mysql_config在/usr/local/bin/而不是上面提到的/usr/local/mysql/bin,所以不需要在path中添加任何东西。

遵循的顺序。

pip install mysqlclient
sudo apt-get install python3-dev libmysqlclient-dev
pip install configparser 
sudo cp /usr/lib/python3.6/configparser.py /usr/lib/python3.6/ConfigParser.py 

然后尝试重新安装MYSQL-python。这对我很有用

对于使用MariaDB而不是MySQL的任何人,解决方案是安装libmariadbclient-dev包,并用正确的名称创建到配置文件的符号链接。

举个例子,这对我来说很管用:

ln -s /usr/bin/mariadb_config /usr/bin/mysql_config

Linux

这对我很有用

yum install python-devel mysql-devel

尝试在OS X Server 10.6.8上安装时遇到类似问题。这是我必须做的。 使用:

MySQL-python 1.2.4b4(源代码) MySQL-5.6.19(二进制安装程序) Python 2.7(二进制安装程序) 注意:安装在virtualenv…

解压源代码,打开'distribute_setup.py'并编辑DEFAULT_VERSION以使用最新版本的分发工具,如下所示:

DEFAULT_VERSION = "0.6.49"

保存。打开'site.cfg'文件,取消mysql_config路径的注释,使它看起来像这样(参考你自己的mysql_config路径):

# The path to mysql_config.
# Only use this if mysql_config is not on your PATH, or you have some weird
# setup that requires it.
mysql_config = /usr/local/mysql/bin/mysql_config

现在clean, build和make将不会失败,'mysql_config' not found错误。 希望这能帮助其他人尝试使用他们的旧xserve:-)