这是我得到的错误

(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

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


当前回答

如果你在你的虚拟环境中安装了MySQL-python,你应该检查pip版本,如果版本高于9.0.1,请更新它

pip install --upgrade pip

其他回答

apt-get install libmysqlclient-dev python-dev

似乎起作用了。

有时错误取决于实际原因。我们有一个通过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恢复到原始状态。

你可以使用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中测试)

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