Python upgrade prompts that the Tkinter module cannot find the solution, pythontkinter

Source: Internet
Author: User

Python upgrade prompts that the Tkinter module cannot find the solution, pythontkinter

1. Install tkinter
In Linux, python does not install the Tkinter module by default,
Copy codeThe Code is 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 more information.
>>> Import Tkinter
Traceback (most recent call last ):
File "<stdin>", line 1, in <module>
ImportError: No module named Tkinter
>>>
We have installed the Tkinter module.
Copy codeThe Code is 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 more information.
>>> Import Tkinter
>>>
Ii. Upgrade Python
Python versions in Linux are not low by default.
View Python version
Copy codeThe Code is as follows:
[Root @ li250-193 ~] # Python-V
Python 2.6.6

New version of DOWN
Copy codeThe Code is as follows:
[Root @ li250-193 ~] # Wget http://www.python.org/ftp/python/2.7.4/Python-2.7.4.tgz

Unzip and install
Copy codeThe Code is 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
...

Check whether Tkinter can be used in the new Python version?
Copy codeThe Code is 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 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
>>>

Why can't I find the tkinter module? Check whether the old version is normal.
Copy codeThe Code is 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 more information.
>>> Import Tkinter
>>>

The old version is okay. Do you need yum install tkinter once?
Copy codeThe Code is 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 to do

The prompt is installed. It does not seem to be a problem with tkinter. Check where the tkinter module is located?
Copy codeThe Code is 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 directory of the old version 2.6, it is estimated that the new version library points to a problem. So I carefully read the README instructions. Reconfigure and install
3. Correctly install the new version of Python
First, modify the Setup. dist file.
Copy codeThe Code is as follows:
[Root @ li250-193 Python-2.7.4] # vim Modules/Setup. dist

Find the following lines and remove the previous well number to open it.
Copy codeThe Code is as follows:
_ Tkinter. c tkappinit. c-DWITH_APPINIT \
-L/usr/local/lib \
-I/usr/local/include \
-Ltk8.5-ltcl8.5 \
-LX11

The fourth line above
-The default value of ltk8.5-ltcl8.5 is 8.2. Please modify the actual tcl/tk version of your system.
Copy codeThe Code is 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 installed 8.5 in the system, so I changed it to 8.5 here.
Save and exit
Install tck-devel and tk-devel
Copy codeThe Code is as follows:
[Root @ li250-193 Python-2.7.4] # yum-y install tcl-devel tk-devel

Start configuration Installation
Copy codeThe Code is 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
...

Check whether the tkinter module can be used in the new Python version.
Copy codeThe Code is 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 more information.
>>> Import Tkinter
>>>
No problem. Check the old version.
Copy codeThe Code is 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 more information.
>>> Import Tkinter
>>>
No problem.
If you enter python-V to check whether the version is the latest, you can do this if not:
Which: python command path
Copy codeThe Code is as follows:
[Root @ li250-193 Python-2.7.4] # which python
/Usr/local/bin/python

Cp past
Copy codeThe Code is as follows:
[Root @ li250-193 Python-2.7.4] # cp python/usr/local/bin/python

4. Upgrade Python to solve the yum version unavailability Problem
After installing many children's shoes
Copy codeThe Code is as follows: cp python/usr/bin/python
Prompt when yum is generated
Copy codeThe Code is 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 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
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
The yum faq:
Http://yum.baseurl.org/wiki/Faq

 
[Root @ lee ~] #

Because the path of the python script created by default in the yum header is
Copy codeThe Code is as follows :#! /Usr/bin/python
You cannot use the old version of python after replacement. I don't know why the new version of Python cannot be identified by yum. The only best solution is to modify the yum header declaration.
Change
Copy codeThe Code is as follows :#! /Usr/bin/python2.6
Here, python2.6 is the default centos version. You can change the default version as needed.


How can Python tkinter exit the black window?

The written program runs with the execution file pythonw.exe with w. No window will be generated.

Py is an open-source software and does not advocate exe packaging.
You only need to put the python interpreter and code together to unpack the package on the client.
You only need to set up a shortcut
Python source code. py
Or
Pythonw source code. py

You can.

There is tkinter in python27. How can I install it?

I checked that Tkinter is built in Python.
You can go:
Search by google:
Tkinter
Then find:
24.1. Tkinter-Python interface to Tcl/Tk-Python v2.7.3
As you can see, use:
Import Tkinter

You can import it.

In addition, you copied the sample code:
From Tkinter import *

Class Application (Frame ):
Def say_hi (self ):
Print "hi there, everyone! "

Def createWidgets (self ):
Self. QUIT = Button (self)
Self. QUIT ["text"] = "QUIT"
Self. QUIT ["fg"] = "red"
Self. QUIT ["command"] = self. quit

Self. QUIT. pack ({"side": "left "})

Self. hi_there = Button (self)
Self. hi_there ["text"] = "Hello ",
Self. hi_there ["command"] = self. say_hi

Self. hi_there.pack ({"side": "left "})

Def _ init _ (self, master = None ):
Frame. _ init _ (self, master)
Self. pack ()
Self. createWidgets ()

Root = Tk ()
App = Application (master = root)
App. mainloop ()

If you are interested in more python-related things, you can search by google:
Crifan Python language summary
Find the tutorial I wrote.

I just wrote a post and tested tkinter. If you need it, I can check it out:
[Record] tossing Tkinter in Python

(No post address is provided here. Please search for the title on google to find the post address)

Related Article

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.