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


当前回答

mySQLdb是mysql的python接口,但它不是mysql本身。显然mySQLdb需要'mysql_config'命令,所以你需要先安装它。

你能确认你是否安装了mysql本身,通过运行“mysql”从shell?这应该给你一个响应,而不是“mysql:命令未找到”。

你用的是哪个linux发行版?Mysql是为大多数linux发行版预先打包的。例如,对于debian / ubuntu,安装mysql非常简单

sudo apt-get install mysql-server

Mysql-config在一个不同的包中,可以从(同样,假设debian / ubuntu)安装:

sudo apt-get install libmysqlclient-dev

如果你使用的是mariadb,将mysql替换掉,然后运行

sudo apt-get install libmariadbclient-dev

参考: https://github.com/JudgeGirl/Judge-sender/issues/4#issuecomment-186542797

其他回答

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

我通过以下步骤解决了这个问题:

sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
sudo python setup.py install

如果你在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

(针对Mac OS X)

我尝试了很多方法,但这组命令最终对我有用。

安装mysql 安装mysql 解除mysql链接 安装mysql-connector-c 将“mysql bin”文件夹添加到“PATH”目录下 导出路径= / usr /地方/地窖/ mysql / 8.0.11 / bin:美元的道路 mkdir /usr/local/Cellar/lib/ 创建符号链接 sudo ln -s /usr/local/Cellar/mysql/8.0.11/lib/libmysqlclient.21。dylib /usr/local/Cellar/lib/libmysqlclient.21.dylib 重新安装openssl(源代码) 最后,安装mysql-client LIBRARY_PATH=$LIBRARY_PATH:/usr/local/opt/openssl/lib/ pip install mysqlclient . sh

更新: 如果这行不通,@vinyll建议在第8步之前运行brew link mysql。

下面是我在Ubuntu 12.04 LTS上使用的:

apt-get install libmysqlclient-dev python-dev

尽管它很有效,但我还是继续做了下面的事情:

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