Win10下 Python3.6.4+PyQt5+Pycharm
一.安装PyQt5
版本:PyQt5-5.9-5.9.1-cp35.cp36.cp37-none-win_amd64.whl
1.下载,官方:https://pypi.python.org/pypi/PyQt5
1.1 安装.whl文件,首先我们要用命令提示符在cmd下,进入.whl文件所在目录。输入 cd c:\Python27\Scripts(你防止whl的目录)
2.有安装了python2和3共存的话选择pip3安装 :
pip3 install PyQt5-5.9-5.9.1-cp35.cp36.cp37-none-win_amd64.whl

或者通过pycharm安装 (重点:下面所有的模块安装都可以通过Pycharm进行傻瓜式安装,非常方便)

二. 安装pyqt5_tools,版本:pyqt5_tools-5.8.2.1.0-cp36-none-win_amd64.whl
1.下载: 官方:https://pypi.python.org/pypi/pyqt5-tools
2.安装: pip3 install pyqt5_tools-5.9.0.1.2-cp36-none-win_amd64.whl

三. 安装sip
什么是sip?
sip是RiverBank(也就是PyQt的开发商)开发的用于PyQt的Python/C++混合编程解决方案。由于Qt框架的复杂性,PyQt并没有使用Cython、SWIG的混合编程方案,而是自己单独做了一套框架。sip包括一个sip工具、SDK和Python Module。
与SWIG类似,使用sip也需要先编写一个『配置文件』,然后使用sip工具『编译』为C++源文件,最后,和Qt库一起编译形成适用于Python的PyQt。
与SWIG不同的是,sip同时以Python Module的形式存在,也就是说,作为Python Module的PyQt,依赖于作为Python Module的sip。而对于SWIG,一旦自动生成的C++生成完毕,整个流程就不再依赖SWIG了。
pycharm安装
调出方式:
settings——project interpreter——然后点加号就可以添加sip模块

四. 在pycharm配置pyqt5
(1) 打开PyCharm,执行快捷键ctrl+alt+s打开设置界面,输入tool,点开external tools,配置qtdesigner。点击左上角的加号,作如下配置:
在Qt Designer的设置中,Program选择PyQt安装目录中 designer.exe 的路径. Work directory 点击后面的 Insert macro 按钮使用变量 $FileDir$ (也可以手工码入)

(2) 设置“PyUIC”-- 这个主要是用来将 Qt界面 转换成 py代码
在PyUIC的设置中,其他的都差不多,Program 写入Python的地址
参数Arguments写入
-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py

下面创建第一个pyqt项目:点击QtDesigner

启动了Designer程序,我们就可以拖控件了。
我们创建窗口程序,选择Man Window,让后点击create。

点击create后,会出现画布(绿色QT标窗口点格阵)和控件(左边)

拖动一个文本label写点内容:

选择项目保存路径进行保存(一般和项目放一起)
但是
这个文件python不能直接运行啊,怎莫办?
此时需要我们上面配置的另一个工具了PyUIC。
选中文件右键,选择我们之前配置的PyUIC

这个命令行工具就会把UI文件转成py文件

代码如下
import sys
import HelloWorld
from PyQt5.QtWidgets import QApplication, QMainWindow
if __name__ == '__main__':
app = QApplication(sys.argv)
MainWindow = QMainWindow()
ui = HelloWorld.Ui_MainWindow()
ui.setupUi(MainWindow)
MainWindow.show()
sys.exit(app.exec_())

点击运行 shift+f10
这将是你第一个python的GUI程序!