【python】python2.7源码安装遇到的问题&&解决

本文解决了Python在CentOS环境下安装过程中出现的Tcl/Tk库缺失、必要模块构建失败等问题,并介绍了如何实现多版本Python的共存及解决Python版本更新后导致的yum工具异常。

摘要生成于 C知道 ,由 DeepSeek-R1 满血版支持, 前往体验 >

1、Error_Info 1: INFO: Can't locate Tcl/Tk libs and/or headers

1.1 解决
yum install tcl-devel
yum install tk-devel
1.2 原因

参考:
You may have to install Tcl and Tk(when using RPM, install the –devel RPM as well) and /or edit the setup.py script to point to the right locations where Tcl/Tk is installed. If you install Tcl/Tk in the default locations, simply rerunning “make” should build the _tkinter extension.

2、Error_Info 2: Python build finished, but the necessary bits to build these modules were not found

错误信息如下示:
Python build finished, but the necessary bits to build these modules were not found:
_bsddb _tkinter bsddb185
dl imageop sunaudiodev

解决:
在CentOS下,可以安装这些依赖包:readline-devel,sqlite-devel,bzip2-devel.i686,openssl-devel.i686,gdbm-devel.i686,libdbi-devel.i686,ncurses-libs,zlib-devel.i686。完成这些安装之后,可以再次编译。

$ yum install readline-devel sqlite-devel bzip2-devel.i686 openssl-devel.i686 gdbm-devel.i686 libdbi-devel.i686 ncurses-libs,zlib-devel.i686
$ make && make install

此解决办法参考:Python编译安装遇到的问题

3、多版本共存解决:安装完python2.7之后,还是显示旧版(2.6)

问题如图:
clipboard.png

解决:

# 把原来的python重命名成python_old,注意不要删除它
$ mv /usr/bin/python /usr/bin/python_old
# 建立新的python的软链接,/usr/local/python27为你刚才的安装目录
$ ln -s /usr/local/python27/bin/python /usr/bin/

4、yum错误:解决因python版本变化,引起的yum问题

问题如图:
clipboard.png

解决:
修改yum脚本(因为yum脚本使用python解析的)

vim /usr/bin/yum
# 进入文件,修改首行#!/usr/bin/python 为旧版的python2.6(这个是我本机的)
#!/usr/bin/python2.6

参考:升级python到最新2.7.x -- linux
success!
over~

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值