服务器之家

服务器之家 > 正文

Centos 6.4 安装Python 2.7 python-pip的详细步骤

时间:2021-12-30 17:08     来源/作者:CentOS教程网

1. 准备工作

下载源码包

?
1
wget http://python.org/ftp/python/2.7.3/Python-2.7.3.tar.bz2

查看是否安装make工具

?
1
2
3
~#rpm -qa|grep make
automake-1.11.1-4.el6.noarch
make-3.81-20.el6.x86_64

如果没有安装make工具

?
1
yum -y install gcc automake autoconf libtool make

查看是否安装zlib库

?
1
2
3
~#rpm -qa|grep zlib
zlib-devel-1.2.3-29.el6.x86_64
zlib-1.2.3-29.el6.x86_64

安装zlib

?
1
yum install zlib-devel

检查是否安装ssl 库

?
1
2
3
4
5
6
~#rpm -qa|grep openssl
openssl-devel-1.0.1e-16.el6_5.x86_64
openssl-static-1.0.1e-16.el6_5.x86_64
openssl098e-0.9.8e-17.el6.centos.2.x86_64
openssl-1.0.1e-16.el6_5.x86_64
openssl-perl-1.0.1e-16.el6_5.x86_64

安装openssl

?
1
yum install openssl*

安装bzip2依赖库

?
1
yum install -y bzip2*

2. 编译安装

?
1
2
3
cp Python-2.7.3.tar.bz2 /usr/src/
tar -jxvf Python-2.7.3.tar.bz2
vi Modules/Setup.dist

找到

?
1
2
3
4
5
6
#SSL=/usr/local/ssl
#_ssl _ssl.c \
#    -DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
#    -L$(SSL)/lib -lssl -lcrypto
......
#zlib zlibmodule.c -I$(prefix)/include -L$(exec_prefix)/lib -lz

把注释去掉

编译

?
1
2
3
4
5
./configure --prefix=/usr/local/python2.7
make all
make install
make clean
make distclean

安装成功

?
1
2
3
4
5
~#/usr/local/python2.7/bin/python2.7
Python 2.7.3 (default, Dec 18 2013, 15:43:35)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>>
?
1
2
cd /usr/local/python2.7
python setup.py install

建立python2.7 软链

?
1
2
3
~#mv /usr/bin/python /usr/bin/python.bak
~#ln -s /usr/local/python2.7/bin/python2.7 /usr/bin/python2.7
~#ln -s /usr/bin/python2.7 /usr/bin/python

3. 解决yum无法使用的问题

?
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
~#yum update
There was a problem importing one of the Python modules
required to run yum. The error leading to this problem was:
 
  No module named yum
 
Please install a package which provides this module, or
verify that the module is installed correctly.
 
It's possible that the above module doesn't match the
current version of Python, which is:
2.7.3 (default, Dec 18 2013, 15:43:35)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-4)]
 
If you cannot solve this problem yourself, please go to
the yum faq at:
 http://yum.baseurl.org/wiki/Faq

因为centos 6.4 下yum默认使用的是python2.6

?
1
2
3
4
5
6
7
8
vi /usr/bin/yum
----------------------------------------------------
#!/usr/bin/python
import sys
try:
  import yum
except ImportError:
.......

修改为

?
1
2
#!/usr/bin/python2.6
........

4. 安装python-pip工具

先安装setup-tools

?
1
2
3
wget https://pypi.python.org/packages/2.7/s/setuptools/setuptools-0.6c11-py2.7.egg --no-check-certificate
chmod +x setuptools-0.6c11-py2.7.egg
sh setuptools-0.6c11-py2.7.egg

安装pip

?
1
2
3
4
5
6
wget https://pypi.python.org/packages/source/p/pip/pip-1.3.1.tar.gz --no-check-certificate
cp pip-1.3.1.tar.gz /usr/src/
tar zxvf pip-1.3.1.tar.gz
cd pip-1.3.1
python setup.py install
ln -s /usr/local/python2.7/bin/pip /usr/bin/pip
标签:

相关文章

热门资讯

yue是什么意思 网络流行语yue了是什么梗
yue是什么意思 网络流行语yue了是什么梗 2020-10-11
背刺什么意思 网络词语背刺是什么梗
背刺什么意思 网络词语背刺是什么梗 2020-05-22
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全
2020微信伤感网名听哭了 让对方看到心疼的伤感网名大全 2019-12-26
蜘蛛侠3英雄无归3正片免费播放 蜘蛛侠3在线观看免费高清完整
蜘蛛侠3英雄无归3正片免费播放 蜘蛛侠3在线观看免费高清完整 2021-08-24
2021年耽改剧名单 2021要播出的59部耽改剧列表
2021年耽改剧名单 2021要播出的59部耽改剧列表 2021-03-05
返回顶部