安装MySQL-python

我试图在我的Ubuntu / Linux Box上安装MySQL-python时遇到了下面的失败。从下面看来,问题似乎是sh: mysql_config: not found可能有人build议我该怎么做?

 rmicro@ubuntu:~$ 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/rmicro/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/rmicro/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 

在Ubuntu上,build议使用发行版本库。 所以安装python-mysqldb应该是直截了当的:

 sudo apt-get install python-mysqldb 

如果你真的想使用PIP来安装,这是前面提到的不是build议的path,但可能的,请看看这个以前问的问题和答案: pip安装mysql-python失败EnvironmentError:mysql_config找不到

这是开发人员非常全面的指南: http : //mysql-python.blogspot.no/2012/11/is-mysqldb-hard-to-install.html

要获得python-mysqld使用pip安装它的所有先决条件(如果您使用的是virtualenv,您将需要执行此操作),请运行以下命令:

 sudo apt-get install build-essential python-dev libmysqlclient-dev 

你有2个选项,如下所述:


像Glaslos这样的发行包build议:

 # sudo apt-get install python-mysqldb 

在这种情况下,您不能使用virtualenv no-site-packages(默认选项),但必须使用:

 # virtualenv --system-site-packages myenv 

使用干净的virtualenv并build立你自己的python-mysql包。

先创buildvirtualenv:

 # virtualenv myvirtualenv # source myvirtualenv/bin/activate 

然后安装构build依赖关系:

 # sudo apt-get build-dep python-mysqldb 

现在你可以安装python-mysql

 # pip install mysql-python 

注意 Ubuntu软件包是python-mysql * db *,python pypi软件包是python-mysql(不含db

 yum install mysql-devel 

它为我工作。

重新阅读错误消息。 它说:

sh:mysql_config:找不到

如果您在Ubuntu Natty上,则mysql_config属于软件包libmysqlclient-dev

  1. find文件夹: sudo find / -name "mysql_config" (假设它是"/opt/local/lib/mysql5/bin"

  2. 将其添加到PATH中: export PATH:export PATH=/opt/local/lib/mysql5/bin:$PATH

  3. 再次安装它

Python或Python3与MySQL,你将需要这些。 这些库使用MySQL的C和Python连接器(你也需要安装C库),它克服了mysqldb库的一些局限性。

  sudo apt-get install libmysqlclient-dev sudo apt-get install python-mysql.connector sudo apt-get install python3-mysql.connector 

这在Python 3上工作

pip安装mysqlclient