>>importTki" />

日韩久久久精品,亚洲精品久久久久久久久久久,亚洲欧美一区二区三区国产精品 ,一区二区福利

Python升級(jí)提示Tkinter模塊找不到的解決方法

系統(tǒng) 1841 0

一、安裝tkinter
在Linux中python默認(rèn)是不安裝Tkinter模塊,

復(fù)制代碼 代碼如下:

[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 " ", line 1, in
ImportError: No module named Tkinter
>>>

我們安裝Tkinter模塊
復(fù)制代碼 代碼如下:

[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
>>>

二、升級(jí)Python
Linux的Python版本默認(rèn)都不叫低
查看Python版本
復(fù)制代碼 代碼如下:

[root@li250-193 ~]# python -V
Python 2.6.6

DOWN新版本
復(fù)制代碼 代碼如下:

[root@li250-193 ~]# wget http://www.python.org/ftp/python/2.7.4/Python-2.7.4.tgz

解壓安裝
復(fù)制代碼 代碼如下:

[root@li250-193 ~]# tar -xf Python-2.7.4.tgz
[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?
復(fù)制代碼 代碼如下:

[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 " ", line 1, in
? File "/root/Python-2.7.4/Lib/lib-tk/Tkinter.py", line 39, in
??? import _tkinter # If this fails your Python may not be configured for Tk
ImportError: No module named _tkinter
>>>

提示找不到tkinter模塊?看看舊版的是不是正常
復(fù)制代碼 代碼如下:

[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一次?
復(fù)制代碼 代碼如下:

[root@li250-193 Python-2.7.4]# yum install tkinter
Loaded plugins: fastestmirror, security
Loading mirror speeds from cached hostfile
?* base: mirror.team-cymru.org
?* extras: mirror.team-cymru.org
?* updates: mirror.team-cymru.org
Setting up Install Process
Package tkinter-2.6.6-36.el6.x86_64 already installed and latest version
Nothing to do

提示已安裝,看來不是tkinter的問題,看看tkinter模塊在哪里?
復(fù)制代碼 代碼如下:

[root@li250-193 Python-2.7.4]# find /usr -name *tkinter.so
/usr/lib64/python2.6/lib-dynload/_tkinter.so

找到一個(gè),在2.6舊版本的目錄下,估計(jì)是因?yàn)樾掳姹編?kù)指向問題。于是認(rèn)真讀了README說明。重新配置安裝
三、正確安裝新版Python
首先修改Setup.dist文件
復(fù)制代碼 代碼如下:

[root@li250-193 Python-2.7.4]# vim Modules/Setup.dist

找到下面這幾行,把前面的井號(hào)去掉打開它
復(fù)制代碼 代碼如下:

_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \
-L/usr/local/lib \
-I/usr/local/include \
-ltk8.5 -ltcl8.5 \
-lX11

以上第四行
-ltk8.5 -ltcl8.5 默認(rèn)是 8.2 ,請(qǐng)你系統(tǒng)實(shí)際tcl/tk版本修改
復(fù)制代碼 代碼如下:

[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

我系統(tǒng)中裝的是8.5,所以這里我改成了8.5
保存退出
安裝tck-devel、tk-devel
復(fù)制代碼 代碼如下:

[root@li250-193 Python-2.7.4]# yum -y install tcl-devel tk-devel

開始配置安裝
復(fù)制代碼 代碼如下:

[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模塊
復(fù)制代碼 代碼如下:

[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
>>>

已經(jīng)沒問題,舊版再看看
復(fù)制代碼 代碼如下:

[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命令路徑
復(fù)制代碼 代碼如下:

[root@li250-193 Python-2.7.4]# which python
/usr/local/bin/python

cp 過去
復(fù)制代碼 代碼如下:

[root@li250-193 Python-2.7.4]# cp python /usr/local/bin/python

四、升級(jí)Python引起yum版本無法使用的問題解決
不少童鞋安裝后就
復(fù)制代碼 代碼如下:
cp python /usr/bin/python

導(dǎo)致yum時(shí)就提示
復(fù)制代碼 代碼如下:

[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:
? http://yum.baseurl.org/wiki/Faq
??
?
[root@lee ~]#

因?yàn)閥um頭部默認(rèn)制定python腳本的路徑就是
復(fù)制代碼 代碼如下:
#! /usr/bin/python

你把舊版的python替換后就是用不了,不知道為何新版Python不能被yum識(shí)別,目前唯一最好解決的方法就是修改yum頭部聲明
改成
復(fù)制代碼 代碼如下:
#! /usr/bin/python2.6

即可,這里的python2.6是我centos默認(rèn)版本,大家的默認(rèn)版本是多少請(qǐng)按實(shí)際情況修改即可


更多文章、技術(shù)交流、商務(wù)合作、聯(lián)系博主

微信掃碼或搜索:z360901061

微信掃一掃加我為好友

QQ號(hào)聯(lián)系: 360901061

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描下面二維碼支持博主2元、5元、10元、20元等您想捐的金額吧,狠狠點(diǎn)擊下面給點(diǎn)支持吧,站長(zhǎng)非常感激您!手機(jī)微信長(zhǎng)按不能支付解決辦法:請(qǐng)將微信支付二維碼保存到相冊(cè),切換到微信,然后點(diǎn)擊微信右上角掃一掃功能,選擇支付二維碼完成支付。

【本文對(duì)您有幫助就好】

您的支持是博主寫作最大的動(dòng)力,如果您喜歡我的文章,感覺我的文章對(duì)您有幫助,請(qǐng)用微信掃描上面二維碼支持博主2元、5元、10元、自定義金額等您想捐的金額吧,站長(zhǎng)會(huì)非常 感謝您的哦!!!

發(fā)表我的評(píng)論
最新評(píng)論 總共0條評(píng)論
主站蜘蛛池模板: 阿坝| 桓台县| 子长县| 东乡族自治县| 齐齐哈尔市| 天峨县| 黔西县| 广西| 尖扎县| 吴旗县| 湘阴县| 河津市| 榆社县| 盐津县| 旬阳县| 浏阳市| 三原县| 临汾市| 天台县| 溆浦县| 东乡| 新泰市| 怀化市| 金阳县| 宁陕县| 洛川县| 六盘水市| 西盟| 海晏县| 西华县| 淄博市| 寿光市| 松江区| 蛟河市| 根河市| 紫金县| 乡宁县| 资兴市| 宝兴县| 阜南县| 新营市|