1

When i try to use pyinstaller with 'KivyMD Kitchen Sink' (--one file --debug --clean) i get this:

File "kivymd\theming.py", line 17, in <module>
File "site-packages\kivy\core\text\__init__.py", line 248, in register
# and pass it in context.config token
OSError: File C:\Users\username\AppData\Local\Temp\_MEI92522\kivymd\fonts/Roboto-Regular.ttfs not found
Failed to execute script main

I try to use:

if hasattr(sys, '_MEIPASS'):
    os.chdir(sys._MEIPASS)

in main.py but nothing changed.

Also, i copied Roboto-Regular.ttf to the main.exe's directory without success.

Pyinstaller is working well with other Kivy apps.

UPDATE:

I found a temporaly solution. I used pyinstaller's --onedir command with main.py instead main.spec file:

wine pyinstaller --onedir main.py

Then, i copied kivymd folder (../site-packages/kivyMD) to my app's folder, and the app started without errors.

Anyways, I would like freeze app as a --onefile, Any suggesions? thanks!

ArtemSBulgakov
  • 973
  • 10
  • 21
Javier Stacul
  • 63
  • 1
  • 2
  • 8
  • Possible duplicate of [Cx\_Freeze cannot find pkg\_resources/\*.\*'](http://stackoverflow.com/questions/42609043/cx-freeze-cannot-find-pkg-resources) – ivan_pozdeev May 07 '17 at 21:15
  • Probably the same effect of mixed slashes as http://stackoverflow.com/questions/42609043/cx-freeze-cannot-find-pkg-resources – ivan_pozdeev May 07 '17 at 21:16
  • Could you reduce your app to a [mcve]? It's either the file not being included, or the execution logic not finding it, possibly due to mixed slashes. – ivan_pozdeev May 07 '17 at 21:17
  • The error code says "Roboto-Regular.ttfs not found" but font's extension should be .ttf – Tech Mar 18 '23 at 11:20

3 Answers3

2

Since KivyMD 0.102.1 there is PyInstaller hook. You can just specify KivyMD's hook directory in your .spec file:

from kivymd import hooks_path as kivymd_hooks_path

a = Analysis(
    # ...
    hookspath=[kivymd_hooks_path],
    # ...
)

You can see Kitchen Sink's pyinstaller.spec file and example in KivyMD's documentation on how to use this hook.


The full pyinstaller.spec file will be:

# -*- mode: python ; coding: utf-8 -*-
import sys
import os
from kivy_deps import sdl2, glew
from kivymd import hooks_path as kivymd_hooks_path
path = os.path.abspath(".")
a = Analysis(
    ["main.py"],
    pathex=[path],
    hookspath=[kivymd_hooks_path],
    win_no_prefer_redirects=False,
    win_private_assemblies=False,
    cipher=None,
    noarchive=False,
)
pyz = PYZ(a.pure, a.zipped_data, cipher=None)
exe = EXE(
    pyz,
    a.scripts,
    a.binaries,
    a.zipfiles,
    a.datas,
    *[Tree(p) for p in (sdl2.dep_bins + glew.dep_bins)],
    debug=False,
    strip=False,
    upx=True,
    name="app_name",
    console=False,
)
ArtemSBulgakov
  • 973
  • 10
  • 21
1

There is no hook for kivymd in pyinstaller, it would not recognize package and therefore will be import errors. So what you can do is write a small hook for pyinstaller so it can be recognized during packing.

Perhaps try using my snippet. Tested on Windows 10

from PyInstaller.utils.hooks import (
    collect_data_files, 
    copy_metadata,
    collect_submodules
)

datas = copy_metadata('kivymd')
hiddenimports = collect_submodules('kivymd')

datas = collect_data_files('kivymd')

Reference to PyInstaller hook https://bitbucket.org/snippets/eiNjel/RgdLkG

Create this file in pyinstaller/hooks and you should be fine.

Jakub Bláha
  • 1,491
  • 5
  • 22
  • 43
aleks
  • 207
  • 1
  • 2
  • 8
  • 2
    A link to a solution is welcome, but please ensure your answer is useful without it: [add context around the link](//meta.stackexchange.com/a/8259) so your fellow users will have some idea what it is and why it’s there, then quote the most relevant part of the page you're linking to in case the target page is unavailable. [Answers that are little more than a link may be deleted.](//stackoverflow.com/help/deleted-answers) – Rob Oct 06 '17 at 01:03
0
  • use pip install auto-py-to-exe
  • run auto-py-to-exe (in cmd)
  • select additional option in auto-py-exe ui
  • in additional file, add kivymd folder which is copied from site package (auto -py-exe(ui))