赞
踩
小插曲:
具体下载哪个版本,我踩了好多坑,此处分享一下踩坑经历。本人电脑安装的是Qt5.12.3。由于没接触过python,因此第一次去官网下载,肯定下载最新的。安装完成之后,又去Qt官网下载PySide2xxx,但是怎么安装都是失败,经过不断的踩坑,推荐一种下载方式。具体如下:
首先去qt官网,查看你要下载的PySide2对应的Python版本,连接:
清华大学开源软件镜像站https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/QtForPython/pyside2/
然后搜索你对应的Qt版本:
由上图可以看出,我需要下载pythone的版本为35~37,因此我下载pythone37.
Customize installation:自定义 安装
install launcher for all users:安装 启动器 给所有的用户
Add Python 3.7 to Path: 添加Python到Path环境变量中(勾选)
Documentation:使用手册
pip:python package indexpython第三方插件管理
tcl/tk and IDLE:python界面操作
Python test suite:python 测试环境
Py lanucher :python启动器
for all users:给所有用户
每个都默认勾选
Install for all users :勾选 给所有用户
Associate files with python:关联python文件
create shortcuts for installed applications:给安装的软件,添加个快捷方式
add python to enviroment variables:将python添加到环境变量中
Precompile standard library:预编译[准备]python标准文件
Customize install location:本地安装位置
最后两个选项不需要勾选,其余的都勾选。
然后就可以点击安装了。
验证方式如下:
- C:\Users\lsyai\Desktop>pip -V
- pip 19.2.3 from d:\program files\python\python37\lib\site-packages\pip (python 3.7)
-
- C:\Users\lsyai\Desktop>python
- Python 3.7.7 (tags/v3.7.7:d7c567b08f, Mar 10 2020, 10:41:24) [MSC v.1900 64 bit (AMD64)] on win32
- Type "help", "copyright", "credits" or "license" for more information.
- >>> print ("hello world")
- hello world
- C:\Users\lsyai\Desktop>pip install PySide2-5.12.3-5.12.3-cp35.cp36.cp37-none-win_amd64.whl
- Processing c:\users\lsyai\desktop\pyside2-5.12.3-5.12.3-cp35.cp36.cp37-none-win_amd64.whl
- Collecting shiboken2==5.12.3 (from PySide2==5.12.3)
- Downloading https://files.pythonhosted.org/packages/53/8a/24c49a3ff59f4a7fe2c9a6737b906f67225ef80ecd8258a8dd54a4dab2f1/shiboken2-5.12.3-5.12.3-cp35.cp36.cp37-none-win_amd64.whl (2.1MB)
- |████████████████████████████████| 2.1MB 50kB/s
- Installing collected packages: shiboken2, PySide2
- Successfully installed PySide2-5.12.3 shiboken2-5.12.3
- WARNING: You are using pip version 19.2.3, however version 20.0.2 is available.
- You should consider upgrading via the 'python -m pip install --upgrade pip' command.
验证PySide2-xxx是否安装成功
新建如下文件:test.py
- import sys
- import random
- from PySide2.QtWidgets import (QApplication, QLabel, QPushButton,
- QVBoxLayout, QWidget)
- from PySide2.QtCore import Slot, Qt
-
- class MyWidget(QWidget):
- def __init__(self):
- QWidget.__init__(self)
-
- self.hello = ["Hallo Welt", "你好,世界", "Hei maailma",
- "Hola Mundo", "Привет мир"]
-
- self.button = QPushButton("Click me!")
- self.text = QLabel("Hello World")
- self.text.setAlignment(Qt.AlignCenter)
-
- self.layout = QVBoxLayout()
- self.layout.addWidget(self.text)
- self.layout.addWidget(self.button)
- self.setLayout(self.layout)
-
- # Connecting the signal
- self.button.clicked.connect(self.magic)
-
- @Slot()
- def magic(self):
- self.text.setText(random.choice(self.hello))
-
- if __name__ == "__main__":
- app = QApplication(sys.argv)
-
- widget = MyWidget()
- widget.resize(800, 600)
- widget.show()
-
- sys.exit(app.exec_())
运行:
C:\Users\lsyai\Desktop>python test.py
结果:
关闭QtCreator并再次打开。
开启学pythoneQt之路。
参考连接:
https://blog.csdn.net/nianmumu/article/details/95522987
https://blog.csdn.net/zscjob/article/details/85337074
https://blog.csdn.net/l1216766050/article/details/84931552
下载连接:
https://www.python.org/downloads/release/python-377/
https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/QtForPython/pyside2/
Copyright © 2003-2013 www.wpsshop.cn 版权所有,并保留所有权利。