pip - pip安装mysql-python EnvironmentError失败: 没有发现mysql_config

  显示原文与译文双语对照的内容

这是我得到的错误


(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
 Downloading MySQL-python-1.2.3.tar.gz (70Kb): 70Kb downloaded
 Running setup.py egg_info for package mysql-python
 sh: mysql_config: not found
 Traceback (most recent call last):
 File"<string>", line 14, in <module>
 File"/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
 metadata, options = get_config()
 File"setup_posix.py", line 43, in get_config
 libs = mysql_config("libs_r")
 File"setup_posix.py", line 24, in mysql_config
 raise EnvironmentError("%s not found" % (mysql_config.path,))
 EnvironmentError: mysql_config not found
 Complete output from command python setup.py egg_info:
 sh: mysql_config: not found

Traceback (most recent call last):

 File"<string>", line 14, in <module>

 File"/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>

 metadata, options = get_config()

 File"setup_posix.py", line 43, in get_config

 libs = mysql_config("libs_r")

 File"setup_posix.py", line 24, in mysql_config

 raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in/home/zjm1126/.pip/pip.log
(mysite)zjm1126@zjm1126-G41MT-S2:~/zjm_test/mysite$ pip install mysql-python
Downloading/unpacking mysql-python
 Running setup.py egg_info for package mysql-python
 sh: mysql_config: not found
 Traceback (most recent call last):
 File"<string>", line 14, in <module>
 File"/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>
 metadata, options = get_config()
 File"setup_posix.py", line 43, in get_config
 libs = mysql_config("libs_r")
 File"setup_posix.py", line 24, in mysql_config
 raise EnvironmentError("%s not found" % (mysql_config.path,))
 EnvironmentError: mysql_config not found
 Complete output from command python setup.py egg_info:
 sh: mysql_config: not found

Traceback (most recent call last):

 File"<string>", line 14, in <module>

 File"/home/zjm1126/zjm_test/mysite/build/mysql-python/setup.py", line 15, in <module>

 metadata, options = get_config()

 File"setup_posix.py", line 43, in get_config

 libs = mysql_config("libs_r")

 File"setup_posix.py", line 24, in mysql_config

 raise EnvironmentError("%s not found" % (mysql_config.path,))

EnvironmentError: mysql_config not found

----------------------------------------
Command python setup.py egg_info failed with error code 1
Storing complete log in/home/zjm1126/.pip/pip.log

如何解决这里问题?

时间:

你的系统上似乎缺少 mysql_config,或者安装程序找不到它。 确保mysql_config真的已经安装。

例如在 debian/ubuntu上,你必须安装软件包:


sudo apt-get install libmysqlclient-dev

也许mysql_config不在你的路径中,你自己编译的MySQL套件就是这种情况。

运行 Mac OSX Mountain Lion,我只是在终端中运行它来修复:


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

在另一个environment,这是最快速的解决我发现- 它将它的添加到路径,但我认为你最好在将它的添加永久( IE 将它的添加到 /etc/paths ) 如果你计划安装

你可以使用MySQL连接器/python

通过 PyPip 安装


pip install mysql-connector-python

更多信息可以在 MySQL连接器/python 1.0.5测试版公告中找到。

在Launchpad上有一个很好的例子,它展示了如何使用库 add- edit-或者删除数据。

上述问题可能有多种答案,下面是聚合解决方案。

对于 Ubuntu:


sudo apt-get update

sudo apt-get install python-dev

sudo apt-get install python-MySQLdb

对于 CentOS:


yum install python-devel mysql-devel

我试图在一个 Amazon EC2实例上安装 mysql-python,我必须安装它:


yum install mysql mysql-devel mysql-common mysql-libs gcc

但后来出现了这个错误:


_mysql.c:29:20: fatal error: Python.h: No such file or directory

所以我安装了:


yum install python-devel

这样做的目的。

...