Why use --add-data
There are many file formats in the program :
Source code .py
Image format .png .jpg .ico etc.
The configuration file .ini .json .xml etc.
Other executable files .bin .exe etc.
Model file .pth etc.
documentation .txt .md etc.
Be careful :except .py outside , Other formats will not compile .
except .py outside , If you want to package other formats , Need to use --add-data Handle , Or manually copy ( It's too much trouble , You can always remember ?)
How to use --add-data?
usage :pyinstaller x.py --add-data=" source address ; Destination address ". windows With ; Division ,linux With : Division
for example : take config All files in the directory are packaged into the destination config Folder ( Does not exist will automatically create ) Next
pyinstaller x.py --add-data ".\\config\\*;.\\config"
Can be used multiple times --add-data
for example :
pyinstaller x.py -n Demo2.0.3 --key [email protected])v -i "res\logo.ico" --add-data=".\*.txt;." --add-data=".\*.json;." --add-data="res\*.*;.\res" --add-data="dist\models\*.*;.\models"
.spec How to use in documents --add-data
# -*- mode: python ; coding: utf-8 -*- block_cipher = pyi_crypto.PyiBlockCipher(key='[email protected])v') a = Analysis(['x.py'], pathex=['D:\\Miniconda3\\envs\\cuda11\\Lib\\site-packages', 'D:\\project\\demo'], binaries=[], datas=[('.\\*.json', '.'), ('res\\*.*', '.\\res'), ('dist\\models\\*.*', '.\\models')], hiddenimports=[], hookspath=[], runtime_hooks=[], excludes=[], win_no_prefer_redirects=False, win_private_assemblies=False, cipher=block_cipher, noarchive=False) pyz = PYZ(a.pure, a.zipped_data, cipher=block_cipher) exe = EXE(pyz, a.scripts, [], exclude_binaries=True, name='Demo2.0.3', debug=False, bootloader_ignore_signals=False, strip=False, upx=True, console=False , icon='res\\logo.ico') coll = COLLECT(exe, a.binaries, a.zipfiles, a.datas, strip=False, upx=True, upx_exclude=[], name='Demo2.0.3')
Analysis Inside datas Is the use of --add-data Corresponding place !
One [] in , There are many. (), Every () Separated by commas , On the left is the program path , On the right is the path into the package !
Write the full path for the deep path !
binaries=[('onnxruntime\\capi\\*.*','\\onnxruntime\\capi')],
--add-binary Same as --add-data similar
————————————————
Thanks to:https://blog.csdn.net/u012219045/article/details/114841287
That year 3w Bought a full set
stay python in , Yes excel Rea