当前位置:网站首页>PyQt5安装配置(PyCharm) 亲测可用
PyQt5安装配置(PyCharm) 亲测可用
2022-08-02 08:33:00 【L**】
PyQt5安装配置(PyCharm)
pip换源
因为在 PyQt5 下载安装时,只能用pip下载,因此首先把pip换源,换为国内源
国内镜像有:
# 清华
https://pypi.tuna.tsinghua.edu.cn/simple/
# 中科大
https://pypi.mirrors.ustc.edu.cn/simple/
# 阿里云
https://mirrors.aliyun.com/pypi/simple/
# 豆瓣
http://pypi.douban.com/simple/
Win+R ,进入运行界面,输入 %APPDATA% ,进入此目录
在该目录下新建名为pip 的文件夹,然后在其中新建文件 pip.ini。(例如:"C:\Users\Administrator\AppData\Roaming\pip\pip.ini")
在文件中填入一下内容并保存(可替换为上述不同的镜像地址):
[global]
index-url = http://pypi.douban.com/simple
[install]
trusted-host=pypi.douban.com
换完源,就可以使用pip下载了
PyQt5下载
首先进入到需要安装PyQt5的环境中,activate pytorch_gpu
之后,执行命令
pip install sip //这个是pyqt开发商提供的支持包
pip install pyqt5
pip install pyqt5-tools
如果改源不成功的话,可以执行以下命令:
pip install sip //这个是pyqt开发商提供的支持包
pip install PyQt5 -i https://pypi.douban.com/simple
pip install PyQt5-tools -i https://pypi.douban.com/simple
配置PyCharm
这里主要添加两个external tool,Qt Designer和pyuic,前者作为打开qt图形化界面进行UI的编辑,后者是将生成的.ui文件转换为.py文件,从而能够运行它。
①创建Qt Designer
在新建的工程下,File->Settings->Tools->External Tools,点击加号:
Name:可自己定义 建议是: Qt Designer
program:XXX\Anaconda3\Lib\site-packages\qt5_applications\Qt\bin\designer.exe Qt Designer的安装路径
Arguments:不填
Working directory: XXX\anaconda\Lib\site-packages\pyqt5_tools
如图所示:
② 创建pyuic
在新建的工程下,`File->Settings->Tools->External Tools`,点击加号:
Name:可自己定义 建议PyUIC
program:E:\anaconda3\envs\pytorch_gpu\python.exe
Arguments:-m PyQt5.uic.pyuic $FileName$ -o $FileNameWithoutExtension$.py
Working directory: $FileDir$

③ 测试
完成后可在pycharm打开Qt Designer,Tools->External Tools->Qt Designer ,这就是我们的目的:

如果一切正常的话:

选择Main Windows,Create
程序猿的第一步当然是仪式性的Hello World
选中一个 label 然后拖拽到window中,Save,建议保存在当前工程目录下!

回到Pycharm 就会多了一个.ui文件
选中该文件,右击,External Tools,PyUIC,这个时候会生成一个.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_())
得到如下结果
然后,游戏结束
边栏推荐
猜你喜欢

PyQt5 (a) PyQt5 installation and configuration, read from the folder and display images, simulation to generate the sketch image

MySQL Workbench 安装及使用

Docker内MySQL主从复制学习,以及遇到的一些问题

ip地址那点事(二)

Pycharm (1) the basic use of tutorial
主流监控系统工具选型及落地场景参考

shell脚本

大厂外包,值得拥有吗?

TiFlash 存储层概览

Biotin-EDA|CAS:111790-37-5| Ethylenediamine biotin
随机推荐
pnpm: Introduction
Write a small game in C (three chess)
pycharm的基本使用教程(1)
【Flink 问题】Flink 如何提交轻量jar包 依赖该如何存放 会遇到哪些问题
[OC学习笔记]ARC与引用计数
R language plotly visualization: use the plotly visualization model to predict the true positive rate (True positive) TPR and false positive rate (False positive) FPR curve under different thresholds
mysql 中 in 的用法
houdini 求出曲线的法向 切线以及副法线
High imitation [Huawei consumer business official website] and wonderful animation analysis: practice embedding JS code in low-code platform
Flink 监控指南 被动拉取 Rest API
JS中的数组方法
C语言基础_共用体
大厂外包,值得拥有吗?
小康股份更名赛力斯,如何走出一条高端产品的“丝绸之路”?
UVM之sequence机制
Jenkins--基础--6.3--Pipeline--语法--脚本式
四字节的float比八字结的long范围大???
Installation and use of pnpm
了解下C# 多线程
OneNote 教程,如何在 OneNote 中创建更多空间?