我试图让一个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 apt-get install libmysqlclient-dev

然后安装

pip install mysqlclient==2.1.0

这对我来说很管用

其他回答

到目前为止,所有解决方案(Linux)都需要sudo或root权限才能安装。 这里有一个解决方案,如果你没有根权限,没有sudo。(no sudo apt install…)

下载libmysqlclient-dev的.deb文件,例如从这个镜像 导航到下载的文件并运行dpkg -x libmysqlclient-dev_<version tag>.deb。这将提取一个名为usr的文件夹。 Symlink ./usr/bin/mysql_config到你的$PATH: ln -s ' pwd ' /usr/bin/mysql_config FOLDER_IN_YOUR_PATH 它现在应该能够找到mysql_config

在Ubuntu 18.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

安装libmysqlclient-dev Sudo apt-get install python-dev sudo apt-get install MySQL-python

注意你也应该安装python-dev,像MySQL-python这样的包是从源代码编译的。pythonx。X-dev包包含针对python进行链接所需的头文件。为什么在Kubuntu 12.04中安装numpy需要python-dev

步骤1:-安装Python3和Python3-dev

sudo apt-get install python3 python3-dev

步骤2:-安装Python和Mysql连接器

sudo apt-get install libmysqlclient-dev

步骤3:-安装python mysql客户端

sudo apt-get install mysqlclient

这将解决你的问题

在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”)。