打开cmd命令行,切换到 D:\python-code\python3-pyqt5-process-csv-data 目录下
D:\python-code\python3-pyqt5-process-csv-data> python -m venv venv3
D:\python-code\python3-pyqt5-process-csv-data> venv3\Scripts\activate
(venv3) D:\python-code\python3-pyqt5-process-csv-data>
(venv3) D:\python-code\python3-pyqt5-process-csv-data> pip install pyqt5
(venv3) D:\python-code\python3-pyqt5-process-csv-data> pip install pyinstaller
创建images.qrc
,注意ico图标放在当前目录下的子目录img中:
<RCC>
<qresource prefix="/" >
<file>img/logo.ico</file>
</qresource>
</RCC>
生成images_pyqt.py
,去文件目录下执行:
(venv3) D:\python-code\python3-pyqt5-process-csv-data> pyrcc5 -o images_pyqt.py images.qrc
最后在代码中import images_pyqt
,并且修改下图片路径,一定要在路径前面加上冒号
:
import images_pyqt
def init_ui(self):
self.setWindowIcon(QIcon(':/img/logo.ico')) # 图标
(venv3) D:\python-code\python3-pyqt5-process-csv-data> pyinstaller --name Madman --onefile --windowed --icon=D:\python-code\python3-pyqt5-process-csv-data\logo.ico -w --paths=D:\python-code\python3-pyqt5-process-csv-data\venv3\Lib\site-packages --paths=D:\python-code\python3-pyqt5-process-csv-data pyqt5_process_csv_data.py