在安装mysqldb python时无法找到mysql_config

2024-04-26 18:57:52 发布

您现在位置:Python中文网/ 问答频道 /正文

我试图让一个Python脚本在我通过ssh连接到的linux服务器上运行。脚本使用mysqldb。我有我需要的所有其他组件,但是当我试图通过如下设置工具安装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?


Tags: inpy脚本configgetlibusrsetup
3条回答

我在Ubuntu 12.04上安装python-mysql,使用的是

pip install mysql-python

首先我有同样的问题:

Not Found "mysql_config"

这对我有效

$ sudo apt-get install libmysqlclient-dev

然后我遇到了这个问题:

...
_mysql.c:29:20: error fatal: Python.h: No existe el archivo o el directorio

compilación terminada.

error: command 'gcc' failed with exit status 1

然后我试着

apt-get install python-dev

然后我很高兴:)

pip install mysql-python
    Installing collected packages: mysql-python
      Running setup.py install for mysql-python
        building '_mysql' extension
        gcc -pthread -fno-strict-aliasing -DNDEBUG -g -fwrapv -O2 -Wall -Wstrict-prototypes -fPIC -Dversion_info=(1,2,4,'beta',4) -D__version__=1.2.4b4 -I/usr/include/mysql -I/usr/include/python2.7 -c _mysql.c -o build/temp.linux-x86_64-2.7/_mysql.o -DBIG_JOINS=1 -fno-strict-aliasing -g
        In file included from _mysql.c:44:0:
        /usr/include/mysql/my_config.h:422:0: aviso: se redefinió "HAVE_WCSCOLL" [activado por defecto]
        /usr/include/python2.7/pyconfig.h:890:0: nota: esta es la ubicación de la definición previa
        gcc -pthread -shared -Wl,-O1 -Wl,-Bsymbolic-functions -Wl,-Bsymbolic-functions -Wl,-z,relro build/temp.linux-x86_64-2.7/_mysql.o -L/usr/lib/x86_64-linux-gnu -lmysqlclient_r -lpthread -lz -lm -lrt -ldl -o build/lib.linux-x86_64-2.7/_mysql.so

Successfully installed mysql-python
Cleaning up...

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

通过从shell运行“mysql”,可以确认是否安装了mysql本身吗?这应该会给您一个响应,而不是“mysql:command not found”。

您正在使用哪个linux发行版?Mysql是为大多数linux发行版预先打包的。例如,对于debian/ubuntu,安装mysql就像

sudo apt-get install mysql-server

mysql config位于另一个包中,可以从以下位置安装(同样,假设是debian/ubuntu):

sudo apt-get install libmysqlclient-dev

如果您使用的是mariadb,则可以使用drop-in替换mysql,然后运行

sudo apt-get install libmariadbclient-dev

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

戴着红帽子

sudo yum install mysql-devel gcc gcc-devel python-devel
sudo easy_install mysql-python

然后成功了。

相关问题 更多 >