Python Qt5环境搭建 (即详细又全面)

1.下载Python

  1. 首先去Python官网下载需要的版本,官网连接:https://www.python.org/

小插曲:

具体下载哪个版本,我踩了好多坑,此处分享一下踩坑经历。本人电脑安装的是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.

 

 

2.安装Python

2.1双击安装文件

Customize installation:自定义 安装

install launcher for all users:安装 启动器 给所有的用户

Add Python 3.7 to Path: 添加Python到Path环境变量中(勾选)

2.2 Optional features

Documentation:使用手册

pip:python package indexpython第三方插件管理

tcl/tk and IDLE:python界面操作

Python test suite:python 测试环境

Py lanucher :python启动器

for all users:给所有用户

每个都默认勾选

2.3.高级选项

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:本地安装位置

最后两个选项不需要勾选,其余的都勾选。

然后就可以点击安装了。

 

2.4.验证安装

验证方式如下:

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

2.5.安装PySide2-xxx

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

结果:

 

3.配置Qt Creator(Win10下)

3.1 帮助>关于插件>选中LanguageClient插件

 

关闭QtCreator并再次打开。

3.2 工具>选项>切换到Language Client选项卡,点击Add按钮

 

3.3.使用Qtcreator新建一个pythone工程并运行

 

开启学pythoneQt之路。

 

参考连接:

https://blog.youkuaiyun.com/nianmumu/article/details/95522987

https://blog.youkuaiyun.com/zscjob/article/details/85337074

https://blog.youkuaiyun.com/l1216766050/article/details/84931552

 

下载连接:

https://www.python.org/downloads/release/python-377/

https://mirrors.tuna.tsinghua.edu.cn/qt/official_releases/QtForPython/pyside2/

 

评论 2
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包

打赏作者

Liu-Eleven

你的鼓励将是我创作的最大动力

¥1 ¥2 ¥4 ¥6 ¥10 ¥20
扫码支付:¥1
获取中
扫码支付

您的余额不足,请更换扫码支付或充值

打赏作者

实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值