I. Tkinter Installation
To install Tkinter in Python 3, you need to upgrade the Python version and recompile it!!!
1. System Version and Python Version
[root@server1 ~]# cat /etc/redhat-release Red Hat Enterprise Linux Server release 7.2 (Maipo) Python Version: 2.7.5
2. Introduction to Tkinter
(1) Introduction
-
tkinter is composed of tcl and tk
-
tcl: Tool Command Language
-
tk: An extension of Tcl's Graphics Toolbox, which provides a variety of standard GUI interface items to facilitate rapid development of advanced applications
(2) Download address
-
Official website links: https://wiki.python.org/moin/TkInter/
-
Download address: https://www.tcl.tk/software/tcltk/download.html
3. tcl and tk installation
(1) Installation
[root@server1 ~]# find / -name "*tkinter.so" ###No result was found [root@server1 ~]# wget https://prdownloads.sourceforge.net/tcl/tcl8.6.8-src.tar.gz [root@server1 ~]# wget https://prdownloads.sourceforge.net/tcl/tk8.6.8-src.tar.gz [root@server1 ~]# tar xf tcl8.6.8-src.tar.gz [root@server1 ~]# cd tcl8.6.8/unix/ [root@server1 unix]# ./configure [root@server1 unix]# make && make install [root@server1 ~]# tar xf tk8.6.8-src.tar.gz [root@server1 ~]# cd tk8.6.8/unix [root@server1 unix]# ./configure [root@server1 unix]# make && make install
(2) Reporting errors:
In file included from /root/tk8.6.8/unix/../generic/tkPort.h:21:0, from /root/tk8.6.8/unix/../generic/tkInt.h:19, from /root/tk8.6.8/unix/../generic/tkStubLib.c:14: /root/tk8.6.8/unix/../generic/tk.h:96:25: fatal error: X11/Xlib.h: No such file or directory # include <X11/Xlib.h>
Solution:
[root@server1 unix]# yum install -y libX11-devel [root@server1 unix]# make && make install
(3) View the results
[root@server1 unix]# ll /usr/local/lib|grep tk -r-xr-xr-x 1 root root 1545763 Oct 16 10:35 libtk8.6.so -rwxr-xr-x 1 root root 5944 Oct 16 10:35 libtkstub8.6.a drwxr-xr-x 6 root root 4096 Oct 16 10:35 tk8.6 -rw-r--r-- 1 root root 4070 Oct 16 10:35 tkConfig.sh [root@server1 ~]# yum install -y tcl-devel tk-devel ###It can be found that we installed version 8.5 8.5.13. [root@server1 ~]# find / -name "libtk*" ###/ usr/lib64/libtk8.5.so is version 8.5, so our version is 8.5 /root/tk8.6.8/unix/libtkstub8.6.a /root/tk8.6.8/unix/libtk8.6.so /usr/lib64/libtk8.5.so /usr/local/lib/libtk8.6.so /usr/local/lib/libtkstub8.6.a
Upgrading Python 2.7 to Python 3.6
1, Download
-
Pthon: https://www.python.org/
-
Download address: https://www.python.org/downloads/
[root@server1 ~]# wget https://www.python.org/ftp/python/3.6.0/Python-3.6.0.tar.xz
2. Compile and Install
[root@server1 ~]# tar xf Python-3.6.0.tar.xz [root@server1 Python-3.6.0]# cd Python-3.6.0/ [root@server1 Python-3.6.0]# vim Modules/Setup.dist ###Open the following items to specify the location of the directory that actually exists in your system 269 _tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \ 271 -L/usr/local/lib \ 273 -I/usr/local/include \ 298 -lX11 ###Change this to our due version number 288 -ltk8.5 -ltcl8.5 \ [root@server1 Python-3.6.0]# ./configure [root@server1 Python-3.6.0]# make && make install
3. Soft Connection
[root@server1 ~]# which python /usr/bin/python [root@server1 ~]# ll /usr/bin/python lrwxrwxrwx. 1 root root 7 Oct 9 20:36 /usr/bin/python -> python2 [root@server1 ~]# ll /usr/bin/python* lrwxrwxrwx 1 root root 22 Oct 16 11:04 /usr/bin/python -> /usr/local/bin/python3 lrwxrwxrwx. 1 root root 9 Oct 9 20:36 /usr/bin/python2 -> python2.7 -rwxr-xr-x. 1 root root 7136 Oct 12 2015 /usr/bin/python2.7 [root@server1 Python-3.6.0]# ll /usr/local/bin/python* lrwxrwxrwx 1 root root 9 Oct 16 11:00 /usr/local/bin/python3 -> python3.6 -rwxr-xr-x 2 root root 12791811 Oct 16 10:59 /usr/local/bin/python3.6 lrwxrwxrwx 1 root root 17 Oct 16 11:00 /usr/local/bin/python3.6-config -> python3.6m-config -rwxr-xr-x 2 root root 12791811 Oct 16 10:59 /usr/local/bin/python3.6m -rwxr-xr-x 1 root root 3097 Oct 16 11:00 /usr/local/bin/python3.6m-config lrwxrwxrwx 1 root root 16 Oct 16 11:00 /usr/local/bin/python3-config -> python3.6-config [root@server1 ~]# rm -f /usr/bin/python [root@server1 ~]# ln -s /usr/local/python3/bin/python3 /usr/bin/python [root@server1 ~]# python --version Python 3.6.0
4. yum Error Reporting Solution
Upgrade will find that yum can not be used!!!
(1) Reporting errors
$ yum File "/usr/bin/yum", line 30 except KeyboardInterrupt, e: ^ SyntaxError: invalid syntax /usr/bin/yum
(2) Solutions
[root@server1 ~]# vim /usr/bin/yum Change the first line "!/ usr/bin/python" to "!/ usr/bin/python 2.7" or "!/ usr/bin/python 2", i.e. your own Python version
5. Check if Tkinter is installed successfully
[root@server1 ~]# python Python 3.6.0 (default, Oct 16 2018, 09:27:46) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import tkinter
3. xlrd Installation (Excel Plug-in)
1, Download
- Download address: https://pypi.org/project/xlrd/#files
[root@server1 ~]# wget https://files.pythonhosted.org/packages/86/cf/bb010f16cefa8f26ac9329ca033134bcabc7a27f5c3d8de961bacc0f80b3/xlrd-1.1.0.tar.gz
2, installation
[root@server1 ~]# tar xf xlrd-1.1.0.tar.gz [root@server1 ~]# cd xlrd-1.1.0/ [root@server1 xlrd-1.1.0]# python setup.py install [root@server1 xlrd-1.1.0]# python
3, test
Python 3.6.0 (default, Oct 15 2018, 11:02:27) [GCC 4.8.5 20150623 (Red Hat 4.8.5-4)] on linux Type "help", "copyright", "credits" or "license" for more information. >>> import xlrd