PyInstaller isn't working with default fonts?
From reddit: https://www.reddit.com/r/pythonarcade/comments/vgn781/arcade_with_pyinstaller/
Creating a game with pyinstaller is failing on loading the default fonts.

EDIT: Was the pyinstalled tutorial followed? I don't understand how it would look in the Temp directory.
Good question. I believe the reporter is following the issue. How was the installer created? Was it done with these steps?
https://api.arcade.academy/en/latest/tutorials/bundling_with_pyinstaller/index.html
Hi all.
I just run the pyinstaller using the commad: pyinstaller test.py
It automatically created an .spec that I edited to include the required font.
Here is the content of the .spec with the path to the font:
# -*- mode: python ; coding: utf-8 -*-
block_cipher = None
a = Analysis(['test.py'],
pathex=[],
binaries=[],
datas=[('C:\\Users\\helde\\miniconda3\\envs\\py39g\\Lib\\site-packages\\arcade\\resources\\fonts\\ttf\\Kenney Blocks.ttf')],
hiddenimports=[],
hookspath=[],
hooksconfig={},
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,
a.binaries,
a.zipfiles,
a.datas,
[],
name='test',
debug=False,
bootloader_ignore_signals=False,
strip=False,
upx=True,
upx_exclude=[],
runtime_tmpdir=None,
console=False,
disable_windowed_traceback=False,
target_arch=None,
codesign_identity=None,
entitlements_file=None )
But this doesnt work either and now the .exe is not created because of an strange error:
(py39g) PS E:\OneDrive - Programa Microsoft Students to Business (S2B)\_GitHub\games> pyinstaller my_test.spec
677 INFO: PyInstaller: 4.8
677 INFO: Python: 3.9.12 (conda)
694 INFO: Platform: Windows-10-10.0.19044-SP0
699 INFO: UPX is not available.
701 INFO: Extending PYTHONPATH with paths
['E:\\OneDrive - Programa Microsoft Students to Business (S2B)\\_GitHub\\games']
discover_hook_directories: Failed to process hook entry point 'hook-dirs = arcade.__pyinstaller:get_hook_dirs': name 'warnings' is not defined
1559 INFO: checking Analysis
1559 INFO: Building Analysis because Analysis-00.toc is non existent
1559 INFO: Initializing module dependency graph...
1563 INFO: Caching module graph hooks...
1572 INFO: Analyzing base_library.zip ...
4285 INFO: Processing pre-find module path hook distutils from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-distutils.py'.
4286 INFO: distutils: retargeting to non-venv dir 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib'
7914 INFO: Caching module dependency graph...
8260 INFO: running Analysis Analysis-00.toc
8288 INFO: Adding Microsoft.Windows.Common-Controls to dependent assemblies of final executable
required by C:\Users\helde\miniconda3\envs\py39g\python.exe
8775 INFO: Analyzing test.py
13010 INFO: Processing pre-find module path hook site from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks\\pre_find_module_path\\hook-site.py'.
13012 INFO: site: retargeting to fake-dir 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\fake-modules'
16826 INFO: Processing module hooks...
16826 INFO: Loading module hook 'hook-difflib.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
16829 INFO: Loading module hook 'hook-distutils.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
16830 INFO: Loading module hook 'hook-distutils.util.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
16833 INFO: Loading module hook 'hook-encodings.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
16943 INFO: Loading module hook 'hook-heapq.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
16946 INFO: Loading module hook 'hook-lib2to3.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
16992 INFO: Loading module hook 'hook-multiprocessing.util.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
16995 INFO: Loading module hook 'hook-pickle.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
17000 INFO: Loading module hook 'hook-PIL.Image.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
17442 INFO: Loading module hook 'hook-PIL.ImageFilter.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
17444 INFO: Loading module hook 'hook-PIL.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
17458 INFO: Loading module hook 'hook-PIL.SpiderImagePlugin.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
17460 INFO: Loading module hook 'hook-pkg_resources.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
18331 WARNING: Hidden import "pkg_resources.py2_warn" not found!
18332 WARNING: Hidden import "pkg_resources.py2_warn" not found!
18333 WARNING: Hidden import "pkg_resources.markers" not found!
18336 INFO: Loading module hook 'hook-setuptools.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
20284 INFO: Loading module hook 'hook-sysconfig.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
20285 INFO: Loading module hook 'hook-xml.etree.cElementTree.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
20286 INFO: Loading module hook 'hook-xml.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
20363 INFO: Loading module hook 'hook-_tkinter.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
20576 INFO: checking Tree
20576 INFO: Building Tree because Tree-00.toc is non existent
20577 INFO: Building Tree Tree-00.toc
20671 INFO: checking Tree
20671 INFO: Building Tree because Tree-01.toc is non existent
20672 INFO: Building Tree Tree-01.toc
20801 INFO: checking Tree
20801 INFO: Building Tree because Tree-02.toc is non existent
20801 INFO: Building Tree Tree-02.toc
20810 INFO: Loading module hook 'hook-setuptools.msvc.py' from 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks'...
20910 INFO: Looking for ctypes DLLs
21203 WARNING: Library wintab32.dll required via ctypes not found
21315 INFO: Analyzing run-time hooks ...
21324 INFO: Including run-time hook 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_subprocess.py'
21327 INFO: Including run-time hook 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgutil.py'
21333 INFO: Including run-time hook 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_multiprocessing.py'
21337 INFO: Including run-time hook 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_inspect.py'
21341 INFO: Including run-time hook 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_pkgres.py'
21348 INFO: Including run-time hook 'C:\\Users\\helde\\miniconda3\\envs\\py39g\\lib\\site-packages\\PyInstaller\\hooks\\rthooks\\pyi_rth_win32api.py'
21376 INFO: Looking for dynamic libraries
21927 INFO: Using Python library C:\Users\helde\miniconda3\envs\py39g\python39.dll
21927 INFO: Found binding redirects:
[]
21943 INFO: Warnings written to E:\OneDrive - Programa Microsoft Students to Business (S2B)\_GitHub\games\build\my_test\warn-my_test.txt
22299 INFO: Graph cross-reference written to E:\OneDrive - Programa Microsoft Students to Business (S2B)\_GitHub\games\build\my_test\xref-my_test.html
22395 INFO: Appending 'datas' from .spec
Traceback (most recent call last):
File "C:\Users\helde\miniconda3\envs\py39g\Scripts\pyinstaller-script.py", line 10, in <module>
sys.exit(run())
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\__main__.py", line 124, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\__main__.py", line 58, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\building\build_main.py", line 793, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\building\build_main.py", line 725, in build
exec(code, spec_namespace)
File "my_test.spec", line 7, in <module>
a = Analysis(['test.py'],
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\building\build_main.py", line 287, in __init__
for name, pth in format_binaries_and_datas(datas, workingdir=spec_dir):
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\building\utils.py", line 491, in format_binaries_and_datas
for src_root_path_or_glob, trg_root_dir in binaries_or_datas:
ValueError: too many values to unpack (expected 2)
(py39g) PS E:\OneDrive - Programa Microsoft Students to Business (S2B)\_GitHub\games> pyinstaller my_test.spec
831 INFO: PyInstaller: 4.8
858 INFO: Platform: Windows-10-10.0.19044-SP0
863 INFO: UPX is not available.
865 INFO: Extending PYTHONPATH with paths
['E:\\OneDrive - Programa Microsoft Students to Business (S2B)\\_GitHub\\games']
discover_hook_directories: Failed to process hook entry point 'hook-dirs = arcade.__pyinstaller:get_hook_dirs': name 'warnings' is not defined
1806 INFO: checking Analysis
1908 INFO: Appending 'datas' from .spec
Traceback (most recent call last):
File "C:\Users\helde\miniconda3\envs\py39g\Scripts\pyinstaller-script.py", line 10, in <module>
sys.exit(run())
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\__main__.py", line 124, in run
run_build(pyi_config, spec_file, **vars(args))
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\__main__.py", line 58, in run_build
PyInstaller.building.build_main.main(pyi_config, spec_file, **kwargs)
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\building\build_main.py", line 793, in main
build(specfile, kw.get('distpath'), kw.get('workpath'), kw.get('clean_build'))
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\building\build_main.py", line 725, in build
exec(code, spec_namespace)
File "my_test.spec", line 7, in <module>
a = Analysis(['test.py'],
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\building\build_main.py", line 287, in __init__
for name, pth in format_binaries_and_datas(datas, workingdir=spec_dir):
File "C:\Users\helde\miniconda3\envs\py39g\lib\site-packages\PyInstaller\building\utils.py", line 491, in format_binaries_and_datas
for src_root_path_or_glob, trg_root_dir in binaries_or_datas:
ValueError: too many values to unpack (expected 2)
EDIT: Was the pyinstalled tutorial followed? I don't understand how it would look in the Temp directory.
I have no idea why it is looking for it in the temp.
After many try-error I figured it out!
Forget about the custom .spec file. Having the test.py as my main file, I just run:
pyinstaller .\test.py --collect-all arcade --onefile -w
The trick part here is the --collect-all arcade [1] which will include everything from the arcade library.
My test, which just shows a blue ball, executable ended up with 55mb, without upx compression.
[1] https://pyinstaller.org/en/stable/man/pyinstaller.html?highlight=runtime_hooks#what-to-bundle-where-to-search
Anything we need to update in pyinstalled tutorial for this?
I believe so.
Would be great to have at least a note mentioning that: in the case of an error related to the fonts or any other resources one need to add the --collect-all arcade to the line pyinstaller main.py --onefile
Does anyone know if this still needs something done?
@einarf I know that we recently finished the resources revamp and that required updating the pyinstaller hook. Is there anything new we should be adding to this in regards to that? Assuming this is just adding a note about this flag to the pyinstaller tutorial I think it should be worth adding so people at least know of it's existence easier.
The pyinstaller hook should include the system resources, Double check is something wrong happened there.
There are resources/system and resources/assets. The assets are resources used in examples only. This way users don't have to bundle 20MB of example stuff in their game. They can include the example assets by overriding the paths.