PySide6 pyside6-deploy 命令 Linux 部署
文章目录
- PySide6 Linux 部署
- 写在前边
- 参考
- 笔者环境
- 前置条件
- 部署案例
- 部署命令
- 运行效果
PySide6 Linux 部署
写在前边
Qt是非常强大的跨平台框架,Qt for Python(PySide/PyQt)作为Qt给Python提供的接口,理论上也可以部署到任意平台上边。这篇文章就是将PySide6``Python实现的代码部署到Linux环境。 其部署出的文件是一个.bin文件。
pyside6-deploy 是 Qt for Python 的部署工具,基于Nuitka
Ccache 是一个编译器缓存。它通过缓存以前的编译并检测何时再次执行相同的编译来加快重新编译 。
参考
pyside6-deploy:Qt for Python 的部署工具¶
Nuitka the Python Compiler
Ccache简介
笔者环境
- 系统环境: Fedora Linux 42 (Workstation Edition)
- Python环境: Python 3.11.X
- Conda/Minconda环境:conda 25.7.0
- PySide环境: PySide6.10.0
前置条件
sudo dnf install gcc gcc-c++ ccache
Conda安装
conda install libpython-static
部署案例
Hello.py
# Copyright (C) 2022 The Qt Company Ltd.
# SPDX-License-Identifier: LicenseRef-Qt-Commercial OR BSD-3-Clause
from __future__ import annotations"""
hello.py
--------This simple script shows a label with changing "Hello World" messages.
It can be used directly as a script, but we use it also to automatically
test PyInstaller or Nuitka. See testing/wheel_tester.py .When compiled with Nuitka or used with PyInstaller, it automatically
stops its execution after 2 seconds.
"""import sys
import random
import platform
import timefrom PySide6.QtWidgets import (QApplication, QLabel, QPushButton,QVBoxLayout, QWidget)
from PySide6.QtCore import Slot, Qt, QTimeris_compiled = "__compiled__" in globals() # Nuitka
auto_quit = "Nuitka" if is_compiled else "PyInst"class MyWidget(QWidget):def __init__(self):super().__init__()self.hello = ["Hallo Welt", "你好,世界", "Hei maailma","Hola Mundo", "Привет мир"]self.button = QPushButton("Click me!")self.text = QLabel(f"Hello World auto_quit={auto_quit}")self.text.setAlignment(Qt.AlignmentFlag.AlignCenter)self.layout = QVBoxLayout()self.layout.addWidget(self.text)self.layout.addWidget(self.button)self.setLayout(self.layout)# Connecting the signalself.button.clicked.connect(self.magic)@Slot()def magic(self):self.text.setText(random.choice(self.hello))if __name__ == "__main__":print("Start of hello.py ", time.ctime())print(" sys.version = ", sys.version.splitlines()[0])# Nuitka and hence pyside6-deploy fails on Python versions <= 3.9# when this module is usedif sys.version_info.minor > 9:print(" platform.platform() = ", platform.platform())app = QApplication()widget = MyWidget()widget.resize(800, 600)widget.show()if auto_quit:milliseconds = 2 * 1000 # run 2 secondQTimer.singleShot(milliseconds, app.quit)retcode = app.exec()print("End of hello.py ", time.ctime())sys.exit(retcode)
部署命令
pyside6-deploy /path/to/hello.py
运行效果

