这是我得到的错误

(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

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


当前回答

在我的情况下,我的数据库在容器上运行,我的flask应用程序在另一个容器上运行,当我尝试更新代码时,应用程序出错了

   Complete output from command python setup.py egg_info:
/bin/sh: 1: mysql_config: not found
/bin/sh: 1: mariadb_config: not found
/bin/sh: 1: mysql_config: not found
Traceback (most recent call last):
  File "<string>", line 1, in <module>
  File "/tmp/pip-build-bya8e734/mysqlclient/setup.py", line 15, in <module>
    metadata, options = get_config()
  File "/tmp/pip-build-bya8e734/mysqlclient/setup_posix.py", line 65, in get_config
    libs = mysql_config("libs")
  File "/tmp/pip-build-bya8e734/mysqlclient/setup_posix.py", line 31, in mysql_config
    raise OSError("{} not found".format(_mysql_config_path))
OSError: mysql_config not found

关键字在堆栈跟踪是

/bin/sh: 1: mysql_config: not found

因为我的烧瓶应用程序运行的地方没有正确配置mysql客户端,所以首先我安装了mysql服务器,然后安装

sudo apt-get install mysql-server-5.7 -y

然后开始使用MySQL

mansoor@LARC-mansur:~/Documents/clients/HR/DevopsSimulator/web$ sudo systemctl start mysql

然后安装flask-mysql包,这次成功了

mansoor@LARC-mansur:~/Documents/clients/HR/DevopsSimulator/web$ sudo pip3 install flask-mysqldb

这是不同的情况,但在这里发帖是因为世界上其他人可能面临同样的问题

其他回答

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

Linux

这对我很有用

yum install python-devel mysql-devel

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

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

sudo apt-get install libmysqlclient-dev

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

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

sudo apt install default-libmysqlclient-dev

你可以使用MySQL连接器/Python

通过PyPip安装

pip install mysql-connector-python

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

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

对于mariadb,安装libmariadbclient-dev而不是libmysqlclient-dev

sudo apt-get install libmariadbclient-dev