如何在 Python 2.6 CentOS 中安装 MySQLdb

声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow 原文地址: http://stackoverflow.com/questions/17620483/
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

提示:将鼠标放在中文语句上可以显示对应的英文。显示中英文
时间:2020-08-19 08:41:47  来源:igfitidea点击:

How to install MySQLdb in Python 2.6 CentOS

pythoncentosmysql-python

提问by kagat-kagat

I am getting this message when I use yum install mysql-pythonto install MySQLdb.

我在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

Update
Result for yum repolist

更新
结果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

回答by jabaldonedo

You can install it via yum, it is case sensitive:

您可以通过 安装它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
...

It works with the following repositories (CentOS 6):

它适用于以下存储库(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

回答by Sukrit Kalra

MySQL-pythonexists in PyPi. Try doing either of the following :

MySQL-python存在于PyPi. 尝试执行以下任一操作:

pip install MySQL-python

or

或者

easy_install MySQL-python

回答by kagat-kagat

Thanks guys for all the help but none of them works for me. I found this interesting articleon web on how to set up the package for Python 2.6 CentOS 5.5, this works for me.

感谢大家的帮助,但没有一个对我有用。我在网上找到了这篇关于如何为 Python 2.6 CentOS 5.5 设置包的有趣文章,这有用

First, I install some stuffs used to build RPMs

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

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

And some dependencies

还有一些依赖

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

Grabbed src RPM

抓取 src RPM

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

And lastly

最后

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

回答by Mulkave

You might want to add the EPEL Repo:

您可能想要添加 EPEL 存储库:

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

then enable it in /etc/yum.repos.d/epel.repo: set enabled=1

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

try yum install gcc-c++ MySQL-pythonafterwards.

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