Linux_升级python 2.7.3(centos)
2016-12-15 11:32
555 查看
首先下载源tar包
可利用linux自带下载工具wget下载,如下所示:
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz 下载完成后到下载目录下,解压
tar -zxvf Python-2.7.3.tgz
进入解压缩后的文件夹
cd Python-2.7.3
在编译前先在/usr/local建一个文件夹python27(作为python的安装路径,以免覆盖老的版本)
mkdir /usr/local/python2.7.3
在解压缩后的目录下编译安装
./configure --prefix=/usr/local/python2.7.3
make
make install
此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字
mv /usr/bin/python /usr/bin/python_old(这里仅仅是改名,将老版本的/usr/bin/python改名为/usr/bin/python_old,如果是python2.6,就改为usr/bin/python_2.6)
再建立新版本python的链接
ln -s /usr/local/python2.7.3/bin/python2.7 /usr/bin/python
这个时候输入
python
就会显示出python的新版本信息
#python安装完毕后,提示找不到ssl模块:[root@localhost ~]# python2.7.5
Python 2.7.5 (default, Jun 3 2013, 11:08:43)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python27/lib/python2.7/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
>>>
2. 查看openssl安装包,发现缺少openssl-devel包
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-20.el5
openssl-0.9.8e-20.el5
3. yum安装openssl-devel
[root@localhost ~]# yum install openssl-devel -y
#查看安装结果
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-26.el5_9.1
openssl-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
4. 重新编译python
#修改Setup文件
vim /usr/software/Python-2.7.5/Modules/Setup
#修改结果如下:
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
5. 重新编译安装python
cd Python-2.7.3./configure --prefix=/usr/local/python2.7.3makemake install
6. 测试,已可正常使用。
[root@localhost ~]# python2.7.5
Python 2.7.5 (default, Jun 3 2013, 14:56:13)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>
转载自:http://www.jb51.net/article/51800.htm http://www.cnblogs.com/yuechaotian/archive/2013/06/03/3115472.html
可利用linux自带下载工具wget下载,如下所示:
wget http://www.python.org/ftp/python/2.7.3/Python-2.7.3.tgz 下载完成后到下载目录下,解压
tar -zxvf Python-2.7.3.tgz
进入解压缩后的文件夹
cd Python-2.7.3
在编译前先在/usr/local建一个文件夹python27(作为python的安装路径,以免覆盖老的版本)
mkdir /usr/local/python2.7.3
在解压缩后的目录下编译安装
./configure --prefix=/usr/local/python2.7.3
make
make install
此时没有覆盖老版本,再将原来/usr/bin/python链接改为别的名字
mv /usr/bin/python /usr/bin/python_old(这里仅仅是改名,将老版本的/usr/bin/python改名为/usr/bin/python_old,如果是python2.6,就改为usr/bin/python_2.6)
再建立新版本python的链接
ln -s /usr/local/python2.7.3/bin/python2.7 /usr/bin/python
这个时候输入
python
就会显示出python的新版本信息
#python安装完毕后,提示找不到ssl模块:[root@localhost ~]# python2.7.5
Python 2.7.5 (default, Jun 3 2013, 11:08:43)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/usr/local/python27/lib/python2.7/ssl.py", line 60, in <module>
import _ssl # if we can't import it, let the error propagate
ImportError: No module named _ssl
>>>
2. 查看openssl安装包,发现缺少openssl-devel包
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-20.el5
openssl-0.9.8e-20.el5
3. yum安装openssl-devel
[root@localhost ~]# yum install openssl-devel -y
#查看安装结果
[root@localhost ~]# rpm -aq|grep openssl
openssl-0.9.8e-26.el5_9.1
openssl-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
openssl-devel-0.9.8e-26.el5_9.1
4. 重新编译python
#修改Setup文件
vim /usr/software/Python-2.7.5/Modules/Setup
#修改结果如下:
# Socket module helper for socket(2)
_socket socketmodule.c timemodule.c
# Socket module helper for SSL support; you must comment out the other
# socket line above, and possibly edit the SSL variable:
#SSL=/usr/local/ssl
_ssl _ssl.c \
-DUSE_SSL -I$(SSL)/include -I$(SSL)/include/openssl \
-L$(SSL)/lib -lssl -lcrypto
5. 重新编译安装python
cd Python-2.7.3./configure --prefix=/usr/local/python2.7.3makemake install
6. 测试,已可正常使用。
[root@localhost ~]# python2.7.5
Python 2.7.5 (default, Jun 3 2013, 14:56:13)
[GCC 4.1.2 20080704 (Red Hat 4.1.2-54)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import ssl
>>>
转载自:http://www.jb51.net/article/51800.htm http://www.cnblogs.com/yuechaotian/archive/2013/06/03/3115472.html
相关文章推荐
- Python动态类型的学习---引用的理解
- Python3写爬虫(四)多线程实现数据爬取
- 垃圾邮件过滤器 python简单实现
- 下载并遍历 names.txt 文件,输出长度最长的回文人名。
- install and upgrade scrapy
- Scrapy的架构介绍
- Centos6 编译安装Python
- 使用Python生成Excel格式的图片
- 让Python文件也可以当bat文件运行
- [Python]推算数独
- Python中zip()函数用法举例
- Python中map()函数浅析
- Python将excel导入到mysql中
- Python在CAM软件Genesis2000中的应用
- 使用Shiboken为C++和Qt库创建Python绑定
- FREEBASIC 编译可被python调用的dll函数示例
- Python 七步捉虫法