转:https://www.bbsmax.com/A/RnJWYvxodq/
一、安装tkinter
在Linux中python默认是不安装Tkinter模块,
[root@li250- ~]# python
Python (r266:, Feb , ::)
[GCC (Red Hat -)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
Traceback (most recent call last):
File , in <module>
ImportError: No module named Tkinter
>>>
我们安装Tkinter模块
[root@li250- ~]# yum -y install tkinter
...
[root@li250- ~]# python
Python (r266:, Feb , ::)
[GCC (Red Hat -)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>>
但新版本的Python依旧不行。
二、正确安装新版Python
加压Python安装包,进入目录后
首先修改Setup.dist文件
cd Python-2.7.13
vi Modules/Setup.dist
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \
-L/usr/local/lib \
-I/usr/local/include \
-ltk8.5 -ltcl8.5 \
-lX11
以上第四行
-ltk8.5 -ltcl8.5 默认是 8.2 ,请你系统实际tcl/tk版本修改
[root@li250- Python-]# rpm -qa | grep ^tk
tk--.el6.x86_64
tkinter--.el6.x86_64
[root@li250- Python-]# rpm -qa | grep ^tcl
tcl--.el6.x86_64
我系统中装的是8.5,所以这里我改成了8.5
保存退出
安装tck-devel、tk-devel
[root@li250-193 Python-2.7.4]# yum -y install tcl-devel tk-devel
接下里请移步博客CentOS 7.3 升级Python 2.7.13参考配置过程,这样会在以后避免很多问题