前言
网上的都不说清楚,怎么打包
1.安装 pyinstaller
pip install pyinstaller
报错问题
这个多数会出现在pyqt6+yolo,而是pyqt5的不会
(pyqt) PS D:\a-down\pyqt> pyinstaller main.py --noconsole --hidden-import PySide6.QtXml
419 INFO: PyInstaller: 6.9.0, contrib hooks: 2024.7
419 INFO: Python: 3.9.19 (conda)
431 INFO: Platform: Windows-10-10.0.22631-SP0
431 INFO: Python environment: C:\Users\15859\.conda\envs\pyqt
433 INFO: wrote D:\a-down\pyqt\main.spec
440 INFO: Module search paths (PYTHONPATH):
['C:\\Users\\15859\\.conda\\envs\\pyqt\\Scripts\\pyinstaller.exe',
'C:\\Users\\15859\\.conda\\envs\\pyqt\\python39.zip',
'C:\\Users\\15859\\.conda\\envs\\pyqt\\DLLs',
'C:\\Users\\15859\\.conda\\envs\\pyqt\\lib',
'C:\\Users\\15859\\.conda\\envs\\pyqt',
'C:\\Users\\15859\\.conda\\envs\\pyqt\\lib\\site-packages',
'D:\\a-down\\pyqt']
675 INFO: checking Analysis
676 INFO: Building Analysis because Analysis-00.toc is non existent
676 INFO: Running Analysis Analysis-00.toc
676 INFO: Target bytecode optimization level: 0
677 INFO: Initializing module dependency graph...
680 INFO: Caching module graph hooks...
696 INFO: Analyzing base_library.zip ...
1614 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\15859\\.conda\\envs\\pyqt\\lib\\site-packages\\PyInstaller\\hooks'...
2091 INFO: Loading module hook 'hook-PyQt6.py' from 'C:\\Users\\15859\\.conda\\envs\\pyqt\\lib\\site-packages\\PyInstaller\\hooks'...
2192 INFO: Loading module hook 'hook-PyQt6.QtCore.py' from 'C:\\Users\\15859\\.conda\\envs\\pyqt\\lib\\site-packages\\PyInstaller\\hooks'...
2863 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\15859\\.conda\\envs\\pyqt\\lib\\site-packages\\PyInstaller\\hooks'...
3379 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\15859\\.conda\\envs\\pyqt\\lib\\site-packages\\PyInstaller\\hooks'...
3610 INFO: Caching module dependency graph...
3688 INFO: Looking for Python shared library...
3696 INFO: Using Python shared library: C:\Users\15859\.conda\envs\pyqt\python39.dll
3696 INFO: Analyzing D:\a-down\pyqt\main.py
3698 INFO: Loading module hook 'hook-PyQt6.QtWidgets.py' from 'C:\\Users\\15859\\.conda\\envs\\pyqt\\lib\\site-packages\\PyInstaller\\hooks'...
3823 INFO: Analyzing hidden import 'PySide6.QtXml'
3826 INFO: Loading module hook 'hook-PySide6.py' from 'C:\\Users\\15859\\.conda\\envs\\pyqt\\lib\\site-packages\\PyInstaller\\hooks'...
Aborting build process due to attempt to collect multiple Qt bindings packages: attempting to run hook for 'PySide6', while hook for 'PyQt6' has already been run! PyInstaller does
not support multiple Qt bindings packages in a frozen application - either ensure that the build environment has only one Qt bindings package installed, or exclude the extraneous bindings packages via the module exclusion mechanism (--exclude command-line option, or excludes list in the spec file).
原因:因为同一个应用程序中尝试同时使用两个不同的Qt绑定(PyQt6和PySide6)
pip uninstall PySide6
2.进行打包
pyinstaller xxx.py --noconsole --add-data "your_path;ultralytics/cfg"
xxx.py是你需要打包的py文件,那么your_path是什么呢?是你的defult.yaml配置文件路径(比如我的就是:E:\ultralytics-main\ultralytics\cfg\default.yaml)
3.最后的处理
会有这两个文件夹,在dist文件夹中有一个文件夹就是你打包py文件的名字,点击去有一个exe
这个1的文件夹就是我们要说的了,pt文件是不会打包进去的,你需要根据你的pt文件路径进行创建一个文件夹(或者你先不创建,根据你的缺失pt文件路径进行创建路径,再放入pt文件)
我的缺失路径就有了放入你打包的py文件同名的文件夹里
放入好pt文件再次打开exe文件,运行成功