Linux 安装mysqldb python接口时找不到mysql_config
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/7475223/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
mysql_config not found when installing mysqldb python interface
提问by user904542
I am trying to get a Python script to run on the linux server I'm connected to via ssh. The script uses mysqldb. I have all the other components I need, but when I try to install mySQLdb via setuptools like so:,
我正在尝试让 Python 脚本在我通过 ssh 连接的 linux 服务器上运行。该脚本使用 mysqldb。我有我需要的所有其他组件,但是当我尝试通过 setuptools 安装 mySQLdb 时:
python setup.py install
I get the following error report related to the mysql_config
command.
我收到以下与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
Has anyone else encountered this error and if so how did you resolve it/what can I do to successfully install mysqldb?
有没有其他人遇到过这个错误,如果有,你是如何解决的/我该怎么做才能成功安装 mysqldb?
回答by amarillion
mySQLdb is a python interface for mysql, but it is not mysql itself. And apparently mySQLdb needs the command 'mysql_config', so you need to install that first.
mySQLdb 是 mysql 的 python 接口,但它不是 mysql 本身。显然 mySQLdb 需要命令 'mysql_config',所以你需要先安装它。
Can you confirm that you did or did not install mysql itself, by running "mysql" from the shell? That should give you a response other than "mysql: command not found".
您能否通过从 shell 运行“mysql”来确认您是否安装了 mysql 本身?这应该给你一个除了“mysql: command not found”之外的响应。
Which linux distribution are you using? Mysql is pre-packaged for most linux distributions. For example, for debian / ubuntu, installing mysql is as easy as
您使用的是哪个 Linux 发行版?大多数 linux 发行版都预先打包了 Mysql。比如debian/ubuntu,安装mysql就这么简单
sudo apt-get install mysql-server
mysql-config is in a different package, which can be installed from (again, assuming debian / ubuntu):
mysql-config 位于不同的包中,可以从(再次假设 debian / ubuntu)安装:
sudo apt-get install libmysqlclient-dev
if you are using mariadb, the drop in replacement for mysql, then run
如果您使用的是 mariadb,则替换 mysql,然后运行
sudo apt-get install libmariadbclient-dev
Reference: https://github.com/JudgeGirl/Judge-sender/issues/4#issuecomment-186542797
参考:https: //github.com/JudgeGirl/Judge-sender/issues/4#issuecomment-186542797
回答by Gary
sudo apt-get install python-mysqldb
须藤 apt-get 安装 python-mysqldb
Python 2.5? Sounds like you are using a very old version of Ubuntu Server (Hardy 8.04?) - please confirm which Linux version the server uses.
蟒蛇2.5?听起来您使用的是非常旧版本的 Ubuntu Server(Hardy 8.04?) - 请确认服务器使用的是哪个 Linux 版本。
python-mysql search on ubuntu package database
Some additional info:
一些额外的信息:
From the README of mysql-python -
来自 mysql-python 的 README -
Red Hat Linux .............
红帽 Linux .....................
MySQL-python is pre-packaged in Red Hat Linux 7.x and newer. This includes Fedora Core and Red Hat Enterprise Linux. You can also build your own RPM packages as described above.
MySQL-python 预先打包在 Red Hat Linux 7.x 和更新版本中。这包括 Fedora Core 和 Red Hat Enterprise Linux。您还可以按照上述方法构建自己的 RPM 包。
Debian GNU/Linux ................
Debian GNU/Linux .....................
Packaged as python-mysqldb
_::
打包为python-mysqldb
_::
# apt-get install python-mysqldb
Or use Synaptic.
或者使用 Synaptic。
.. _python-mysqldb
: http://packages.debian.org/python-mysqldb
.. _ python-mysqldb
: http://packages.debian.org/python-mysqldb
Ubuntu ......
Ubuntu ......
Same as with Debian.
与 Debian 相同。
Footnote: If you really are using a server distribution older than Ubuntu 10.04 then you are out of official support, and should upgrade sooner rather than later.
脚注:如果您确实在使用早于 Ubuntu 10.04 的服务器发行版,那么您将失去官方支持,应该尽早升级。
回答by thoslin
I fixed it by installing libmysqlclient:
我通过安装 libmysqlclient 修复了它:
sudo apt-get install libmysqlclient16-dev
回答by John Livingston
The MySQL-python
package is using the mysql_config
command to learn about the mysql
configuration on your host. Your host does not have the mysql_config
command.
该MySQL-python
软件包正在使用该mysql_config
命令来了解mysql
您主机上的配置。您的主机没有该mysql_config
命令。
The MySQL development libraries package (MySQL-devel-xxx) from dev.mysql.com provides this command and the libraries needed by the MySQL-python package. The MySQL-devel
packages are found in the download - community server area. The MySQL development library package names start with MySQL-devel
and vary based MySQL version and linux platform (e.g. MySQL-devel-5.5.24-1.linux2.6.x86_64.rpm
.)
来自 dev.mysql.com 的 MySQL 开发库包 (MySQL-devel-xxx) 提供了此命令和 MySQL-python 包所需的库。该MySQL-devel
社区服务器区-包在下载找到。MySQL 开发库包名称MySQL-devel
以 MySQL 版本和 linux 平台(例如MySQL-devel-5.5.24-1.linux2.6.x86_64.rpm
.)
Note that you do not need to install mysql server.
请注意,您不需要安装 mysql 服务器。
回答by samwize
The commands (mysql too) mPATH might be missing.
命令(也是 mysql)mPATH 可能丢失。
export PATH=$PATH:/usr/local/mysql/bin/
export PATH=$PATH:/usr/local/mysql/bin/
回答by Mayank R Jain
I got the same error while trying to install mysql-python
.
我在尝试安装时遇到了同样的错误mysql-python
。
This is how I fixed it.
这就是我修复它的方式。
sudo PATH=/usr/local/mysql/bin/:$PATH pip install mysql-python
The problem was that the installer could not find the mysql_config in the default path. Now it can ..and it worked..
问题是安装程序在默认路径中找不到 mysql_config。现在它可以..并且它起作用了..
15 warnings generated.
clang -bundle -undefined dynamic_lookup -Wl,-F. build/temp.macosx-10.8-intel-2.7/_mysql.o -L/usr/local/mysql/lib -lmysqlclient_r -lz -lm -lmygcc -o build/lib.macosx-10.8-intel-2.7/_mysql.so -arch x86_64
Successfully installed mysql-python
Cleaning up...
Hope this helps.
希望这可以帮助。
Thanks.
谢谢。
回答by xtornasol512
I was installing python-mysql
on Ubuntu 12.04 using
我python-mysql
在 Ubuntu 12.04 上安装使用
pip install mysql-python
First I had the same problem:
首先我遇到了同样的问题:
Not Found "mysql_config"
This worked for me
这对我有用
$ sudo apt-get install libmysqlclient-dev
Then I had this problem:
然后我遇到了这个问题:
...
_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
Then I tried with
然后我试过
apt-get install python-dev
And then I was happy :)
然后我很高兴:)
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...
回答by zhaozhi
I fixed this problem with the following steps:
我通过以下步骤解决了这个问题:
sudo apt-get install libmysqlclient-dev
sudo apt-get install python-dev
sudo python setup.py install
回答by ebarch
You need to install the python-dev package:
你需要安装 python-dev 包:
sudo apt-get install python-dev
回答by flyer
I encountered the same problem, just added the path where *mysql_config* resided to the environment variable PATH and it worked for me.
我遇到了同样的问题,只是将 *mysql_config* 所在的路径添加到环境变量 PATH 中,它对我有用。