这是我得到的错误

(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

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


当前回答

在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

其他回答

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

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

ln -s /usr/bin/mariadb_config /usr/bin/mysql_config
apt-get install libmysqlclient-dev python-dev

似乎起作用了。

你应该先安装mysql:

yum install python-devel mysql-community-devel -y

然后安装mysqlclient:

pip install  mysqlclient

你可以使用MySQL连接器/Python

通过PyPip安装

pip install mysql-connector-python

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

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

在我的情况下,我的数据库在容器上运行,我的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

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