Python 2.7 及 Python 3.7 安装PySimpleGUI27和PySimpleGUI

撰写日期:2020年2月1日

PySimpleGUI是一个Python的GUI框架,以Tkinter、Pyqt和wxPython为后端,简化了Python GUI编程,可以说是目前创建python界面最方便快捷的框架。

PySimpleGUI的GitHub地址为:https://github.com/PySimpleGUI/PySimpleGUI
其中的readme即为文档。

另外文档也可以阅读这里:https://pysimplegui.readthedocs.io/en/latest/#platforms

目前,PySimpleGUI已经停止支持Python 2(截止至2020-1-1),所以建议使用Python 3.

一、系统环境

  • Windows 10 64bit 1909

二、Python 3.7 安装PySimpleGUI

Python 3最好使用Python 3.7.2(包含)及其之前的版本。Python 3.7.3及其之后的版本使用table colors时有问题。
详情参见官方文档:

Warning - tkinter + Python 3.7.3 and later, including 3.8 has problems

The version of tkinter that is being supplied with the 3.7.3 and later versions of Python is known to have a problem with table colors. Basically, they don't work. As a result, if you want to use the plain PySimpleGUI running on tkinter, you should be using 3.7.2 or less. 3.6 is the version PySimpleGUI has chosen as the recommended version for most users.

Python 3.7 安装PySimpleGUI极其简单,直接输入如下命令即可:

pip install PySimpleGUI

三、Python 2.7 安装PySimpleGUI27

下面主要说明Python 2下的安装,我使用的版本是Python 2.7.5 32bit。安装之前先看这句话,引用自官方文档:

As of 9/25/2018 both Python 3 and Python 2.7 are supported when using tkinter version of PySimpleGUI! The Python 3 version is named PySimpleGUI. The Python 2.7 version is PySimpleGUI27. They are installed separately and the imports are different. See instructions in Installation section for more info. None of the other ports can use Python 2.

也就是说,在Python 2.7下,安装包名称是PySimpleGUI27,而不是PySimpleGUI

直接采用pypi上面的pip install PySimpleGUI27并不能得到正确安装该包,而且可能会报Could not find a version that satisfies....的错误。

(1)安装之前,最好更新pip

更新命令为:python -m pip install --upgrade pip

(2)采用豆瓣源安装PySimpleGUI27及依赖包typing
pip install PySimpleGUI27 -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
pip install typing -i http://pypi.douban.com/simple/ --trusted-host pypi.douban.com
  • PySimpleGUI27依赖future包,如果不自动安装future包,请手动安装。
  • 另外还需要安装typing包。
  • 采用豆瓣的源,可以加快速度。选项 --trusted-host pypi.douban.com 是为了获得ssl证书的认证

安装完成之后,采用如下代码测试安装是否成功:

import PySimpleGUI27
PySimpleGUI27.main()
(3)测试安装

安装成功的话,上面的代码回产生下图结果:

Python 2.7 及 Python 3.7 安装PySimpleGUI27和PySimpleGUI_第1张图片
PySimpleGUI27测试安装

参考链接

  • CSDN: python pip 安装一些包找不到的问题 Could not find a version that satisfies....
  • https://github.com/PySimpleGUI/PySimpleGUI
  • https://pysimplegui.readthedocs.io/en/latest/

你可能感兴趣的:(Python 2.7 及 Python 3.7 安装PySimpleGUI27和PySimpleGUI)