赞
踩
打开Anaconda Prompt
,执行以下命令创建虚拟环境并激活
# 创建名为 myEnv, python版本为3.9 的虚拟环境
conda create -n myEnv python=3.9
# 激活创建的虚拟环境
conda avtivate myEnv
使用pip
安装Pyside6
,通过-i
指定国内镜像源作为索引源进行加速。默认情况下,pip
会从Python Package Index(PyPI)
上下载库文件进行安装,国内下载比较慢。
# 使用百度镜像源进行加速
pip install pyside6 -i https://mirror.baidu.com/pypi/simple
或者
# 永久配置国内百度镜像源
pip config set global.index-url https://mirror.baidu.com/pypi/simple
# 安装pyside6
pip install pyside6
https://pypi.mirrors.ustc.edu.cn/simple/
http://pypi.douban.com/simple/
http://mirrors.aliyun.com/pypi/simple/
https://pypi.tuna.tsinghua.edu.cn/simple/
打开PyCharm
并新建项目
如果没有上述新建虚拟环境对应的解释器,点击Add Interpreter
新建,流程如下:
选择“当前窗口”或者打开“新窗口”
点击File
-> Settings
-> Tools
-> External Tools
,点击+
。添加以下3个选项: Pyside6-Designer
、 Pyside6-UIC
和 Pyside6-rcc
。
名称 | 内容 |
---|---|
Name | 名称,自定义 |
Group | 默认即可,也可自定义 |
Program | designer.exe的位置 |
Arguments | 带的参数,不填 |
Working directory | 命令执行的目录,$FileDir$ |
效果就是:在Working directory
下 执行 Program Argument
名称 | 内容 |
---|---|
Name | 名称,自定义 |
Group | 默认即可,也可自定义 |
Program | pyside6-uic.exe的位置 |
Arguments | 带的参数,$FileName$ -o ui_$FileNameWithoutExtension$.py |
Working directory | 命令执行的目录,$FileDir$ |
名称 | 内容 |
---|---|
Name | 名称,自定义 |
Group | 默认即可,也可自定义 |
Program | pyside6-rcc.exe的位置 |
Arguments | 带的参数,$FileName$ -o $FileNameWithoutExtension$_rc.py |
Working directory | 命令执行的目录,$FileDir$ |
配置完成,点击OK
即可。右键点击项目,如下图所示:
新建1个.py
文件,将下面这段代码复制进去并运行:
import sys from PySide6.QtWidgets import QApplication, QMainWindow, QLabel class MyWindow(QMainWindow): def __init__(self): super().__init__() self.setWindowTitle("PySide6 Test") self.setGeometry(100, 100, 300, 200) self.label = QLabel("Hello Pyside6", self); self.label.setGeometry(100, 100, 100, 10) if __name__ == "__main__": app = QApplication(sys.argv) window = MyWindow() window.show() sys.exit(app.exec())
如果出现GUI界面,则说明安装成功。
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。