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

这对我来说很管用

其他回答

我有这个问题,并解决了如果添加一个符号链接到mysql_config。

我用自制软件安装了mysql,并在输出中看到了这一点。

Error: The `brew link` step did not complete successfully

根据你如何得到mysql,它将在不同的地方。在我的例子中,/usr/local/Cellar/mysql 一旦你知道了它的位置,你就应该能够创建一个符号链接,指向python正在寻找它的地方。/usr/local/mysql

这对我很管用。

ln -s /usr/local/Cellar/mysql/<< VERSION >>/bin/mysql_config   /usr/local/mysql/bin/mysql_config

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

我也有同样的问题。我通过遵循本教程在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

我认为在2020年解决这个问题最方便的方法是使用另一个python包。我们不需要安装任何其他二进制软件。

试试这个

PIP安装mysql-connector-python

然后

进口mysql.connector Mydb = mysql.connector.connect( 主机= " ", 用户= " ", passwd = " ", 数据库= " " ) Cursor = mydb。光标(缓冲= True) 游标。执行(“显示表;”) 游标。Execute ('insert into test values (null, "a",10)') mydb.commit () mydb.disconnect ()

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

apt-get install libmysqlclient-dev python-dev

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

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