我试图让一个Python脚本在我通过ssh连接到的linux服务器上运行。脚本使用mysqldb。我有我需要的所有其他组件,但当我试图通过setuptools安装mySQLdb,像这样:

python setup.py install

我得到以下与mysql_config命令相关的错误报告。

sh: mysql_config: command not found
Traceback (most recent call last):
  File "setup.py", line 15, in <module>
    metadata, options = get_config()
  File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 43, in get_config
    libs = mysql_config("libs_r")
  File "/usr/lib/python2.5/MySQL-python-1.2.3/setup_posix.py", line 24, in mysql_config
    raise EnvironmentError("%s not found" % (mysql_config.path,))
EnvironmentError: mysql_config not found

有没有其他人遇到过这个错误,如果是的话,你是如何解决的/我能做什么才能成功安装mysqldb?


当前回答

我也有同样的问题。我通过遵循本教程在Ubuntu 16.04上使用python3-dev安装Python来解决这个问题:

sudo apt-get update
sudo apt-get -y upgrade
sudo apt-get install -y python3-pip
sudo apt-get install build-essential libssl-dev libffi-dev python3-dev

现在你可以设置你的虚拟环境:

sudo apt-get install -y python3-venv
pyvenv my_env
source my_env/bin/activate

其他回答

mysql -python包正在使用mysql_config命令来了解主机上的mysql配置。您的主机没有mysql_config命令。

来自dev.mysql.com的MySQL开发库包(MySQL-dev -xxx)提供了该命令和MySQL-python包所需的库。MySQL-devel包可以在下载社区服务器区找到。MySQL开发库包名称以MySQL-devel开头,根据MySQL版本和linux平台的不同而有所不同(例如MySQL- develop -5.5.24-1.linux2.6.x86_64.rpm)。

注意,您不需要安装mysql服务器。

python 3.5.2 +任何未来版本

Sudo apt-get install libmysqlclient-dev python-dev

实际误差是

gcc ... -I/usr/include/python2.7 ...

_mysql.c:29:20: error: Python.h: No such file or directory

如果你不能安装python-dev或python-devel包,你可以从http://hg.python.org/下载所需版本的python源文件,并将头文件放在适当的文件夹中进行包含

This method is only for those who know that Mysql is installed but still mysql_config can't be find. This happens if python install can't find mysql_config in your system path, which mostly happens if you have done the installation via .dmg Mac Package or installed at some custom path. The easiest and documented way by MySqlDB is to change the site.cfg. Find the mysql_config which is probably in /usr/local/mysql/bin/ and change the variable namely mysql_config just like below and run the installation again. Don't forget to un-comment it by removing "#"

以下更改

mysql_config = /usr/local/bin/mysql_config

to

mysql_config = /usr/local/ mysql_bin /mysql_config"

这取决于系统中的路径。

顺便说一下,我在更改site.cfg后使用python安装

sudo /System/Library/Frameworks/ python .framework/Versions/2.7/bin/python setup.py install

在MacOS (OS/X) Catalina上,我发现我需要这样做:

 export PATH=$PATH:/usr/local/bin/:/usr/local/mysql-5.7.16-osx10.11-x86_64/bin/

在我的电脑上,mysql命令在/usr/local/bin(来自标准MacOS安装程序,而不是“brew”)。