Python upgrade prompts Tkinter The module cannot find a workaround _python

Source: Internet
Author: User
Tags stdin python script

I. Installation of Tkinter
in Linux, Python defaults to not installing the Tkinter module,

Copy Code code as follows:

[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 the more information.
>>> Import Tkinter
Traceback (most recent call last):
File "<stdin>", line 1, in <module>
Importerror:no module named Tkinter
>>>

We install the Tkinter module
Copy Code code as follows:

[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 the more information.
>>> Import Tkinter
>>>

Second, upgrade Python
The Python version of Linux is not called low by default
View Python version
Copy Code code as follows:

[root@li250-193 ~]# Python-v
Python 2.6.6

Down new version
Copy Code code as follows:

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

Decompression Installation
Copy Code code as follows:

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

See if the new version of Python can use Tkinter?
Copy Code code as follows:

[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 the 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 <module>
Import _tkinter # If This fails your Python may is configured for Tk
Importerror:no module named _tkinter
>>>

Hint that the Tkinter module is not found? See if the old version is normal.
Copy Code code as follows:

[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 the more information.
>>> Import Tkinter
>>>

The old version of the No problem, you need to yum install Tkinter once?
Copy Code code as follows:

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

Hint has been installed, it seems not tkinter problem, see Tkinter module where?
Copy Code code as follows:

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

Find one, in the 2.6 old version of the directory, estimated because the new version of the library points to the problem. So carefully read the readme instructions. Reconfigure installation
third, the correct installation of the new Python
First modify the Setup.dist file
Copy Code code as follows:

[root@li250-193 python-2.7.4]# Vim Modules/setup.dist

Find the following lines, remove the front number and open it.
Copy Code code as follows:

_tkinter _tkinter.c tkappinit.c-dwith_appinit \
-l/usr/local/lib \
-i/usr/local/include \
-ltk8.5-ltcl8.5 \
-lx11

Line Fourth above
-ltk8.5-ltcl8.5 default is 8.2, please change your system actual TCL/TK version
Copy Code code as follows:

[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

I got 8.5 in my system, so I changed it to 8.5.
Save exit
Install Tck-devel, Tk-devel
Copy Code code as follows:

[root@li250-193 python-2.7.4]# yum-y Install Tcl-devel tk-devel

Start Configuration Installation
Copy Code code as follows:

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

See if the new Python can use the Tkinter module
Copy Code code as follows:

[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 the more information.
>>> Import Tkinter
>>>

No problem, old version, look again.
Copy Code code as follows:

[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 the more information.
>>> Import Tkinter
>>>

I'm fine.
If you are typing python-v directly to view the version is not up to date, if it is not possible to do so:
which the Python command path
Copy Code code as follows:

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

CP Past
Copy Code code as follows:

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

Four, upgrade Python caused Yum version is not available to solve problems
Many children's shoes after installation
Copy Code code as follows:
CP Python/usr/bin/python

Prompt when Yum is caused
Copy Code code as follows:

[Root@lee ~]# Yum
There was a problem importing one of the Python modules
Required to run Yum. The error leading to this problem is:

No module named Yum

Please install a package which provides this module, or
Verify that's 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 are cannot solve this problem yourself
The Yum FAQ at:
Http://yum.baseurl.org/wiki/Faq


[Root@lee ~]#

Because the Yum header defaults to the path of the Python script is
Copy Code code as follows:
#! /usr/bin/python

You replace the old version of Python is not used, do not know why the new version of Python can not be Yum recognized, the only best solution is to modify the Yum header statement
Change into
Copy Code code as follows:
#! /usr/bin/python2.6

Can, here's python2.6 is my CentOS default version, everyone's default version is how much please modify the actual situation can be

Contact Us

The content source of this page is from Internet, which doesn't represent Alibaba Cloud's opinion; products and services mentioned on that page don't have any relationship with Alibaba Cloud. If the content of the page makes you feel confusing, please write us an email, we will handle the problem within 5 days after receiving your email.

If you find any instances of plagiarism from the community, please send an email to: info-contact@alibabacloud.com and provide relevant evidence. A staff member will contact you within 5 working days.

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.