如果遇到问题也查找不到资料时,可以认真阅读安装文件下的README说明,或者可以得到帮助。
本次环境为redhat 6.4、python2.7.9
linux 图形化显示需要安装一些依赖包,比如libx11、tkinter
yum install libX11 –y
yum install libX11-devel.x86_64 –y
yum install tkinter –y
这里需要注意的,如果你的python并不是linux系统自带的版本,而是后来安装的,比如redhat 6.4 自带的python为2.6,我的python是后来安装的2.7.9,这里就需要修改一下配置文件
tk与tcl是tkinter所依赖的软件包,查看其安装的版本
[[email protected] ~]# rpm -qa | grep ^tk
tk-8.5.7-5.el6.x86_64
tkinter-2.6.6-64.el6.x86_64
[[email protected] ~]# rpm -qa | grep ^tcl
tcl-8.5.7-6.el6.x86_64
去掉以下几行前面的注释#,并修改tk与tcl的版本
[[email protected] ~]# cd /software/Python-2.7.9/Modules/
[[email protected] Modules]# vi Setup.dist
_tkinter _tkinter.c tkappinit.c -DWITH_APPINIT \
-L/usr/local/lib \
-I/usr/local/include \
-ltk8.5 -ltcl8.5 \
-lX11
安装tk与tcl的辅助软件包
yum install tcl-devel tk-devel -y
重新编译安装python,zlib是其他模块所依赖的包,不需要时可以不安装
[[email protected] Python-2.7.9]# ./configure prefix=/opt/soft/python/ --with-zlib=/usr/share/doc/zlib-1.2.3
make
make install
其中make 的时候会报
Python build finished, but the necessary bits to build these modules were not found
然后是列出的一些模块,可以单独安装这些模块,在这里并不影响,继续安装即可
测试安装是否成功
[[email protected] Python-2.7.9]# python
Python 2.7.9 (default, Apr 14 2016, 10:51:01)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import Tkinter
>>>
下载 easygui : http://easygui.sourceforge.net/
将easygui解压后CP到python根目录
[[email protected] software]# unzip easygui-0.97.zip
Archive: easygui-0.97.zip
creating: easygui/
inflating: easygui/easygui.py
inflating: easygui/python_and_check_logo.gif
inflating: easygui/python_and_check_logo.jpg
inflating: easygui/python_and_check_logo.png
inflating: easygui/zzzzz.gif
extracting: easygui/__init__.py
[[email protected] software]# cp -r easygui /opt/soft/python/
[[email protected] software]# python
Python 2.7.9 (default, Apr 14 2016, 11:11:33)
[GCC 4.4.7 20120313 (Red Hat 4.4.7-3)] on linux2
Type "help", "copyright", "credits" or "license" for more information.
>>> import easygui
>>> flavor = easygui.choicebox("你现在用的是哪个品牌的电脑", choices = [‘苹果‘,‘联想‘,‘华硕‘])