Package the dependencies to the target program directory
concern
I developed an application using PySide2, and to make it easier for other people to use it, I packaged it as a *.exe using PyInstaller in one-folder mode, i.e., the resulting target file is a folder that contains the *.exe file and all the files that the *.exe depends on.
Open the folder and the screenshot is below:
Everything's going great, but there's this one problem.The program relies on several files (*.png, *.txt) to run, and without packing them into the target directory for me, the *.exe can't find the files and won't run.
method settle an issue
* Use the configuration file .spec to specify that dependent files are packaged together.
Configuration file focus section content:
a = Analysis([''], pathex=['E:\\7-Pycharm\\contrl_sys_ui'], binaries=[], datas=[("./other", "other"), ("./QtDesigner", "QtDesigner")],
The datas option gives the (path to original, path to destination) tuple. The original file path is the path of the file/folder on your computer. When packaging, PyInstaller will copy the original file to the target file path according to the original file path we specified.
The target file path is the directory where the packaged generated target program is located as the following directory.
For example, my package directory is . /dist/MainWindow, then PyInstaller will copy . /other and . /QtDesigner to the . /dist/MainWindow directory.
In the packaged target file, you can find all the folders we want to pack together are also packed over, the screenshot is as follows:
pyinstaller packaged exe with dependencies
pyinstaller configuration file should not be set on .spec, otherwise updating the configuration file will not take effect, use () to get the path of the exe execution.
The above is a personal experience, I hope it can give you a reference, and I hope you can support me more.