如何在Python 2.6 CentOS中安装MySQLdb

时间:2013-07-12 17:18:16

标签: python centos mysql-python

当我使用yum install mysql-python安装MySQLdb时,我收到此消息。

Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sin3.sg.voxel.net
 * extras: mirrors.sin3.sg.voxel.net
 * updates: mirrors.sin3.sg.voxel.net
base                                                      | 3.7 kB     00:00
extras                                                    | 3.4 kB     00:00
updates                                                   | 3.4 kB     00:00
Setting up Install Process
No package mysql-python available.
Error: Nothing to do

更新
yum repolist

的结果
root@server [~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.sin3.sg.voxel.net
 * extras: mirrors.sin3.sg.voxel.net
 * updates: mirrors.sin3.sg.voxel.net
base                                     | 3.7 kB     00:00
extras                                   | 3.4 kB     00:00
updates                                  | 3.4 kB     00:00
repo id              repo name                        status
base                 CentOS-6 - Base                  6,019+362
extras               CentOS-6 - Extras                13
updates              CentOS-6 - Updates               802+140
repolist: 6,834

4 个答案:

答案 0 :(得分:15)

您可以通过yum进行安装,它区分大小写:

[root@localhost ~]# yum install MySQL-python
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.nfsi.pt
 * extras: mirrors.nfsi.pt
 * updates: mirrors.nfsi.pt
Setting up Install Process
Resolving Dependencies
--> Running transaction check
---> Package MySQL-python.x86_64 0:1.2.3-0.3.c1.1.el6 will be installed
--> Finished Dependency Resolution
...

它适用于以下存储库(CentOS 6):

[root@localhost ~]# yum repolist
Loaded plugins: fastestmirror
Loading mirror speeds from cached hostfile
 * base: mirrors.nfsi.pt
 * extras: mirrors.nfsi.pt
 * updates: mirrors.nfsi.pt
repo id      repo name            status
base         CentOS-6 - Base      6.381
extras       CentOS-6 - Extras    12
updates      CentOS-6 - Updates   458
repolist: 6.851

答案 1 :(得分:4)

PyPi中存在

MySQL-python。尝试执行以下任一操作:

pip install MySQL-python

easy_install MySQL-python

答案 2 :(得分:2)

谢谢大家的帮助,但没有一个对我有用。我在网上找到了关于如何为Python 2.6 CentOS 5.5设置软件包的interesting article,这对我有用。

首先,我安装一些用于构建RPM的东西

yum -y install rpm-build gcc-c++

和一些依赖

yum -y install readline-devel openssl-devel gmp-devel ncurses-devel
yum -y install gdbm-devel expat-devel libGL-devel libX11-devel tcl-devel tk-devel
yum -y install tix-devel sqlite-devel db4-devel

抓住src RPM

rpm -Uvh http://mirrors.geekymedia.com/centos/python26-2.6-geekymedia1.src.rpm

最后

yum install -y mysql-devel
curl http://superb-sea2.dl.sourceforge.net/project/mysql-python/mysql-python/1.2.3/MySQL-python-1.2.3.tar.gz | tar zxv
cd MySQL-python-1.2.3
python setup.py build
python setup.py install

答案 3 :(得分:0)

您可能想要添加EPEL Repo:

/bin/rpm -Uvh http://download.fedoraproject.org/pub/epel/6/i386/epel-release-6-8.noarch.rpm creates=/etc/yum.repos.d/epel.repo

然后在/etc/yum.repos.d/epel.repo中启用它:设置enabled=1

之后尝试yum install gcc-c++ MySQL-python