PyCharm

python解释器环境

用conda管理,在python中创建,不要在pycharm中创建

conda create -n pytest
conda activate pytest
安装后, conda install pip

安装pycharm

安装后, 添加conda 的pytest环境下的python解释器

pyside6

参考: https://doc.qt.io/qtforpython-6/quickstart.html

安装: pip install pyside6

xgj.py

import sys
import random
from PySide6 import QtCore, QtWidgets, QtGui

class MyWidget(QtWidgets.QWidget):
    def __init__(self):
        super().__init__()

        self.hello = ["Hallo Welt", "Hei maailma", "Hola Mundo", "Привет мир","你好"]

        self.button = QtWidgets.QPushButton("Click me!")
        self.text = QtWidgets.QLabel("Hello World",
                                     alignment=QtCore.Qt.AlignCenter)

        self.layout = QtWidgets.QVBoxLayout(self)
        self.layout.addWidget(self.text)
        self.layout.addWidget(self.button)

        self.button.clicked.connect(self.magic)

    @QtCore.Slot()
    def magic(self):
        self.text.setText(random.choice(self.hello))

if __name__ == "__main__":
    app = QtWidgets.QApplication([])

    widget = MyWidget()
    widget.resize(800, 600)
    widget.show()

    sys.exit(app.exec())

配置pycharm

增加两个外部工具

名称: pyside6-uic
程序:D:\miniconda3\envs\pytest\Scripts\pyside6-uic.exe
参数:$FileName$ -o ui_$FileNameWithoutExtension$.py
工作目录: $FileDir$

名称:pyside6-designer
程序:D:\miniconda3\envs\pytest\Scripts\pyside6-designer.exe
工作目录:$FileDir$

该方式下创建main.ui, 生成 ui_main.py

xgj.py

import sys
from PySide6.QtWidgets import QApplication, QMainWindow
from ui_main import Ui_MainWindow

class MainWindow(QMainWindow):

    def __init__(self):
        super().__init__()

        self.ui = Ui_MainWindow()

        self.ui.setupUi(self)


if __name__ == '__main__':
    app = QApplication(sys.argv)

    window = MainWindow()

    window.show()

    sys.exit(app.exec())

pycharm快捷键

  • shift F10:执行程序

  • Ctrl+Shift+F10:运行当前文件

  • 双击shift:搜索

  • shift F9: 开始调试

  • F9:执行断点

  • ctrl F8: 设置、取消断点

nuitka打包

官网: https://github.com/Nuitka/Nuitka

安装: pip install nuitka

nuitka –mingw64 –standalone –onefile –windows-disable-console –output-dir=out –show-progress –show-memory –plugin-enable=pyside6 –windows-icon-from-ico=tool.ico xgj.py

打包过程中按要求补充安装相应的包。

打包选项:
–mingw64
–standalone 独立环境,这是必须的(否则拷给别人无法使用)
–windows-disable-console 没有CMD控制窗口
–output-dir=out 生成exe到out文件夹下面去
–show-progress 显示编译的进度,很直观
–show-memory 显示内存的占用
–enable-plugin=pyqt5
–plugin-enable=pyside6
–plugin-enable=numpy 打包numpy,pandas,matplotlib模块的刚需
–plugin-enable=torch 打包pytorch的刚需
–plugin-enable=tensorflow 打包tensorflow的刚需
–windows-icon-from-ico=你的.ico 软件的图标(启动文件的图标,不是窗口图标)
–windows-company-name=Windows下软件公司信息
–windows-product-name=Windows下软件名称
–windows-file-version=Windows下软件的信息
–windows-product-version=Windows下软件的产品信息
–windows-file-description=Windows下软件的作用描述
–windows-uac-admin=Windows下用户可以使用管理员权限来安装
–linux-onefile-icon=Linux下的图标位置
–onefile 像pyinstaller一样打包成单个exe文件
–include-package=复制比如numpy,PyQt5 这些带文件夹的叫包或者轮子
–include-module=复制比如when.py 这些以.py结尾的叫模块

正文完
 
评论(没有评论)