I want to include a folder and its contents within pyinstaller. I have a folder named 'etc' and it has a file named sbom.json. I am following the post mentioned tree, but I keep getting an error saying The system cannot find the path specified: '..\\etc
when I run pyinstaller fetch_sbom_packages.spec
command.
(The fetch_sbom_packages.py has dependencies with dsapi.py and shared.py).
Here is my folder structure. I want to include the etc folder and its contents
Here is the fetch_sbom_packages.spec
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['fetch_sbom_packages.py'],
pathex=[],
binaries=[],
datas=[],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
Tree('..\\etc', prefix='etc\\'),
a.datas,
[],
name='fetch_sbom_packages',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)
That post is from 9+ years ago.
What you want to do is add a tuple to the datas
parameter in the Analysis for the folder you want to be included in the compiled app.
For example:
# -*- mode: python ; coding: utf-8 -*-
a = Analysis(
['fetch_sbom_packages.py'],
pathex=[],
binaries=[],
datas=[("./etc", "./etc")],
hiddenimports=[],
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='fetch_sbom_packages',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=True,
disable_windowed_traceback=False,
argv_emulation=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None,
)