这是我得到的错误

(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

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


当前回答

Linux

这对我很有用

yum install python-devel mysql-devel

其他回答

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

pip install --upgrade pip

对于centos用户:

Yum install -y mysql-devel python-devel python-setuptools

then

pip安装MySQL-python


如果这个解决方案不工作,并打印gcc编译错误如下: _mysql.c:29:20: error: Python.h:没有这样的文件或目录

你需要指定Python.h的路径,就像这样: pip install——global-option=build_ext——global-option="-I/usr/include/python2.6

如果你使用MAC 全局安装

brew install mysql

然后像这样导出路径

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

或者在你的venv里,随便你喜欢

pip install MySQL-Python

注意:全局为python3,因为Mac可以同时有python2和3

pip3 install MySQL-Python

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

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

sudo apt-get install libmysqlclient-dev

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

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

sudo apt install default-libmysqlclient-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恢复到原始状态。