我试图让一个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?


当前回答

我认为,下面的行可以在终端上执行

 sudo ln -s /usr/local/zend/mysql/bin/mysql_config /usr/sbin/

mysql_config目录用于MacOSx上的zend服务器。你可以在linux上这样做

sudo ln -s /usr/local/mysql/bin/mysql_config /usr/sbin/

这是默认的linux mysql目录。

其他回答

同样,我得到了同样的问题 我通过以下步骤解决了这个问题: 首先运行这个命令

sudo apt-get install libmysqlclient-dev

然后安装

pip install mysqlclient==2.1.0

这对我来说很管用

如果你在macOS上,并且已经通过brew install安装了mysql@5.7:

安装mysql-connector-c Brew unlink mysql@5.7 酿造链接—覆盖—先运行mysql@5.7,看看哪些符号链接被覆盖 Brew link—overwrite—强制mysql@5.7用mysql@5.7实际覆盖mysql相关的符号链接 PIP安装mysqlclient

python 3.5.2 +任何未来版本

Sudo apt-get install libmysqlclient-dev python-dev

使用apt-get install python-mysqldb

Python 2.5吗?听起来你使用的是一个非常旧的Ubuntu服务器(Hardy 8.04?) -请确认服务器使用的Linux版本。

Python-mysql搜索ubuntu包数据库

一些附加信息:

来自mysql-python -的README

红帽Linux .............

MySQL-python是在Red Hat Linux 7中预先打包的。X和更新的。这 包括Fedora核心和红帽企业Linux。你也可以 按照上面的描述构建自己的RPM包。

Debian GNU/Linux ................

打包为python-mysqldb_::

# apt-get install python-mysqldb

或者使用Synaptic。

…_python-mysqldb: http://packages.debian.org/python-mysqldb

Ubuntu ......

和Debian一样。

脚注:如果你使用的是比Ubuntu 10.04更老的服务器,那么你已经不受官方支持了,应该尽早升级。

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