Python升级提⽰Tkinter模块不到的解决⽅法
⼀、安装tkinter
在Linux中python默认是不安装Tkinter模块,
复制代码代码如下:
[root@li250-193 ~]# python
Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
ImportError: No module named Tkinter
>>>
我们安装Tkinter模块
复制代码代码如下:
[root@li250-193 ~]# yum -y install tkinter
...
[root@li250-193 ~]# python
Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>>
⼆、升级Python
Linux的Python版本默认都不叫低
查看Python版本
复制代码代码如下:
[root@li250-193 ~]# python -V
Python 2.6.6
DOWN新版本
复制代码代码如下:
[root@li250-193 ~]# wget /ftp/python/2.7.4/Python-2.
解压安装
复制代码代码如下:
[root@li250-193 ~]# tar -xf Python-2.
[root@li250-193 ~]# cd Python-2.7.4
[root@li250-193 Python-2.7.4]# ./configure
...
[root@li250-193 Python-2.7.4]# make
...
[root@li250-193 Python-2.7.4]# make install
...
看看新版本Python是否可以使⽤Tkinter?
复制代码代码如下:
[root@li250-193 Python-2.7.4]# ./python
Python 2.7.4 (default, Apr 12 2013, 08:03:09)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
File "/root/Python-2.7.4/Lib/lib-tk/Tkinter.py", line 39, in <module>
import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
>>>
提⽰不到tkinter模块?看看旧版的是不是正常
复制代码代码如下:
[root@li250-193 Python-2.7.4]# python
Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>>
旧版的没问题,难道需要yum install tkinter⼀次?python安装教程非常详细
复制代码代码如下:
[root@li250-193 Python-2.7.4]# yum install tkinter
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
* base:
* extras:
* updates:
Setting up Install Process
Package tkinter-2.6.6-36.el6.x86_64 already installed and latest version
Nothing to do
提⽰已安装,看来不是tkinter的问题,看看tkinter模块在哪⾥?
复制代码代码如下:
[root@li250-193 Python-2.7.4]# find /usr -name *tkinter.so
/
usr/lib64/python2.6/lib-dynload/_tkinter.so
到⼀个,在2.6旧版本的⽬录下,估计是因为新版本库指向问题。于是认真读了README说明。重新配置安装三、正确安装新版Python
⾸先修改Setup.dist⽂件
复制代码代码如下:
[root@li250-193 Python-2.7.4]# vim 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-193 Python-2.7.4]# rpm -qa | grep ^tk
tk-8.5.7-5.el6.x86_64
tkinter-2.6.6-36.el6.x86_64
[root@li250-193 Python-2.7.4]# rpm -qa | grep ^tcl
tcl-8.5.7-6.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
开始配置安装
复制代码代码如下:
[root@li250-193 Python-2.7.4]# ldconfig
[root@li250-193 Python-2.7.4]# ./configure
...
[root@li250-193 Python-2.7.4]# make
...
[root@li250-193 Python-2.7.4]# make install
.
..
看下新版Python是否可以使⽤tkinter模块
复制代码代码如下:
[root@li250-193 Python-2.7.4]# ./python
Python 2.7.4 (default, Apr 12 2013, 08:49:11)
[GCC 4.4.6 20120305 (Red Hat 4.4.6-4)] on linux2
Type "help", "copyright", "credits" or "license" for more information. >>> import Tkinter
>>>
已经没问题,旧版再看看
复制代码代码如下:
[root@li250-193 Python-2.7.4]# /usr/bin/python2.6
Python 2.6.6 (r266:84292, Feb 22 2013, 00:00:18)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information. >>> import Tkinter
>>>
也没问题
如果直接敲⼊python -V查看版本是不是最新的,如果不是可以这么⼲:which出python命令路径
复制代码代码如下:
[root@li250-193 Python-2.7.4]# which python
/usr/local/bin/python
cp 过去
复制代码代码如下:
[root@li250-193 Python-2.7.4]# cp python /usr/local/bin/python
四、升级Python引起yum版本⽆法使⽤的问题解决
不少童鞋安装后就
复制代码代码如下:
cp python /usr/bin/python
导致yum时就提⽰
复制代码代码如下:
[root@lee ~]# yum
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.4 (default, Apr  9 2013, 17:12:56)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)]
If you cannot solve this problem yourself, please go to
the yum faq at:
/wiki/Faq
[root@lee ~]#
因为yum头部默认制定python脚本的路径就是
复制代码代码如下:
#! /usr/bin/python
你把旧版的python替换后就是⽤不了,不知道为何新版Python不能被yum识别,⽬前唯⼀最好解决的⽅法就是修改yum头部声明
改成
复制代码代码如下:
#! /usr/bin/python2.6
即可,这⾥的python2.6是我centos默认版本,⼤家的默认版本是多少请按实际情况修改即可

版权声明:本站内容均来自互联网,仅供演示用,请勿用于商业和其他非法用途。如果侵犯了您的权益请与我们联系QQ:729038198,我们将在24小时内删除。