linux下安装Tkinter及python升级

1.  首先安装Tkinter模块:yum -y install tkinter

2.在python下运行import Tkinter发现正确,但是使用的是默认版的python2.4.3

5.  再次运行import Tkinter后报错:

 

Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
Traceback (most recent call last):
  File "<stdin>", line 1, in <module>
  File "/usr/local/python27/lib/python2.7/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

 6. 运行yum install tk-devel tcl-devel ;

 

7.  下载python2.7.9后,在编译前先在/usr/local建一个文件夹mkdir /usr/local/python27,使用tar   zxvf    test.tgz  -C  dir解压python2.7.9,在解压后的目录下运行./configure --prefix=/usr/local/python27 --enable-unicode=ucs4,通过make&make install编译;

 

mkdir  /usr/local/python27
./configure --prefix=/usr/local/python27 --enable-unicode=ucs4
make clean
make 
make install

    重新编译python2.7.9。

 

8.建立新版本python的链接ln -s /usr/local/python27/bin/python2.7 /usr/bin/python,运行python的话即可看到引入新版本python2.7.9。再试用import Tkinter,完成。

 

 其中出现的问题:

1. 因为需要升级到更高版本,系统中又有2.6.8,版本很乱故删除掉python2.6的所有东西又重新在python为2.7.9时运行的yum install tk-devel tcl-devel ;使tk及tcl为最新版,然后又重新编译的2.7.9。最后的tk及tcl版本如下:rpm -qa |grep ^tk

tk-devel-8.4.13-5.el5_1.1
tk-8.4.13-5.el5_1.1
tk-devel-8.4.13-5.el5_1.1
tkinter-2.4.3-56.el5
tk-8.4.13-5.el5_1.1

       rpm -qa |grep ^tc

tcsh-6.14-14.el5
tcl-devel-8.4.13-6.el5
tcl-devel-8.4.13-6.el5
tcp_wrappers-7.6-40.7.el5
tcpdump-3.9.4-14.el5
tcl-8.4.13-6.el5
tcl-8.4.13-6.el5
tcp_wrappers-7.6-40.7.el5

   在unix下使用Tkinter,可参考如下资料:https://python.org/topics/tkinter/ 

你可能感兴趣的:(python)