Moving the .spec in a subfolder without breaking the build #9473
|
Hi! I made a small project, this is the folder structure: As you can see I have the .spec file in the root folder of the project, but I'd like to have it in the .windows folder. With the current project structure the following .spec works: # -*- mode: python ; coding: utf-8 -*-
import os
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
project_root = os.path.abspath(".")
import sys
sys.path.insert(0, project_root)
datas = []
datas += collect_data_files("assets")
datas += collect_data_files("l10n")
a = Analysis(
['src/main.py'],
pathex=[project_root],
binaries=[],
datas=datas,
hiddenimports=collect_submodules('src'),
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='Tutel',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
icon='assets/icons/tutel.ico',
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='Tutel'
)I tried moving the .spec and changing it like this: # -*- mode: python ; coding: utf-8 -*-
import os
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
project_root = os.path.abspath(".")
import sys
sys.path.insert(0, project_root)
datas = []
datas += collect_data_files(os.path.join(project_root, "assets"))
datas += collect_data_files(os.path.join(project_root, "l10n"))
a = Analysis(
collect_data_files(os.path.join(project_root, "src/main.py")),
pathex=[project_root],
binaries=[],
datas=datas,
hiddenimports=collect_submodules(os.path.join(project_root, "src")),
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='Tutel',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
icon=os.path.join(project_root, 'assets', 'icons', 'tutel.ico'),
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='Tutel'
)This worked like a charm for another project (a simpler one which produces just the .exe, not a directory) but when I try to build this the program doesn't start. What am I missing? |
Replies: 2 comments 11 replies
|
For starters, |
|
Ok so, this works: # -*- mode: python ; coding: utf-8 -*-
import os
from PyInstaller.utils.hooks import collect_data_files, collect_submodules
project_root = os.path.abspath(".")
import sys
sys.path.insert(0, project_root)
datas = []
datas += collect_data_files("assets")
datas += collect_data_files("l10n")
a = Analysis(
['../src/main.py'],
pathex=[project_root],
binaries=[],
datas=datas,
hiddenimports=collect_submodules("src"),
hookspath=[],
hooksconfig={},
runtime_hooks=[],
excludes=[],
noarchive=False,
optimize=0,
)
pyz = PYZ(a.pure)
exe = EXE(
pyz,
a.scripts,
a.binaries,
a.datas,
[],
name='Tutel',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
icon="../assets/icons/tutel.ico",
)
coll = COLLECT(
exe,
a.binaries,
a.zipfiles,
a.datas,
strip=False,
upx=True,
name='Tutel'
)So yeah the issue was definitely the importing of the assets being messed up. I definitely need to check the .spec files in the other project, they work but I want to remove the weird parts (the os.path.join calls). Thank you very much! |

The only asset in this other project seems to be the .ico file, which is probably not referenced by python code and is used only for the PyInstaller build. And similarly, you probably do not even need the
collect_submodules()call, since all imports are successfully discovered by our import analysis (i.e., no indirect imports and no lazy-loaded imports).In the project that we're discussing here, you have at least one asset (the
assets/configs/default_appsettings.json) and failing to collect that probably results in a run-time error.