1) 通过命令pip install PyQt5进行安装
本地若安装了Anaconda,里面会自带PyQt5,但自带的PyQt5可能会有版本不兼容问题,比如最后将XXX.ui文件转换为XXX.py文件时,会报模块找不到错误
此时在anaconda的cmd界面重新安装PyQt5即可
Traceback (most recent call last):
File "C:UsersXXXXXAppDataLocalContinuumanaconda3lib
unpy.py", line 193, in _run_module_as_main
"__main__", mod_spec)
File "C:UsersXXXXXAppDataLocalContinuumanaconda3lib
unpy.py", line 85, in _run_code
exec(code, run_globals)
File "C:UsersXXXXXAppDataLocalContinuumanaconda3libsite-packagesPyQt5uicpyuic.py", line 26, in <module>
from PyQt5 import QtCore
ImportError: DLL load failed: The specified module could not be found.
2) PyCharm中配置PyQt5
具体详细请参照https://blog.csdn.net/esting_tang/article/details/81082504
a) 打开PyCharm,打开File—>Settings—>External Tools, 点击加号来添加自己的工具,做如下配置:
Name: QtDesigner
Group: Qt
Programs: F:anacondaLibraryindesigner.exe(自己本地designer.exe的路径)
Working directory:$ProjectFileDir$
完成后点“OK”,现在QtDesigner就配置好了, 就可以直接在PyCharm中打开它来画界面了
b) 要在PyCharm中把界面的.ui文件转换为.py文件,同样在External Tools中点击加号来配置pyuic,做如下配置:
Name:Pyuic
Group:Qt
Program:F:anacondapython.exe(自己本地python.exe的路径)
Arguments:-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
Working directory:$FileDir$
至此就全部配置完成
c) 测试配置是否OK
回到PyCharm,Tools—>Qt—>QtDesigner,点击即可打开designer
保存文件至当前pycharm目录,文件后缀名为xxx.ui
在Pycharm中,右键点击该文件,Qt --> Pyuic,执行后,对应的新的xxx.py文件会生成在xxx.ui文件同级目录下