Attribute error on #:import in kv file

125 views
Skip to first unread message

WvdB63

unread,
Aug 9, 2021, 9:26:43 AM8/9/21
to Kivy users support
I have a Python 3.9 / Kivy 2.0.0 app running perfectly well on Windows10 within PyCharm. 
When building the exe using PyInstaller (4.5.1) the app builds, the exe starts but crashes at a certain point.
The exception is: 

  File "appguides.py", line 72, in <module>
  File "kivy\lang\builder.py", line 373, in load_string
  File "kivy\lang\parser.py", line 402, in __init__
  File "kivy\lang\parser.py", line 508, in parse
  File "kivy\lang\parser.py", line 477, in execute_directives
AttributeError: module 'pmuix' has no attribute 'data_table'

At line 72 in appguides.py I have:

from appguideskv import style, APPGVersionItem
Builder.load_string(style)

and in appguideskv I have the following import statements:

#:import Factory kivy.factory.Factory
#:import dp kivy.metrics.dp
#:import PMDataTable pmuix.data_table
#:import PMTextField pmuix.textfields
#:import PMIconButton pmuix.iconbutton

The project structure is as follows:
myapp
    > folder: pmuix
           file: __init__.py
           file: data_table.py
           file: textfields.py
           file: iconbutoon.py

Obviously the #:import statement is not handled correctly by PyInstaller (?) or .....?
Who can help me out here? I am stuck ....


Elliot Garbus

unread,
Aug 9, 2021, 2:33:28 PM8/9/21
to kivy-...@googlegroups.com

Pyinstaller does not understand kv, and so does not see the kv import statements.

You can add the import statements to the hidden imports section of your spec file or in your main python file import those modules.

I prefer to do the imports in the main python module, and have a spec file I can generally reuse with minimal customization.

 

Pycharm will let you know that the imported modules are not being used, just ignore that.

Here is the spec file I use for creating apps.  I create a directory at the same level as the source code under a project, call ProjectDist.  I mention this because I use relative paths to identify files.

This will build a ‘one folder bundle’  I package the exe and the directory using https://jrsoftware.org/isinfo.php  This creates a professional looking installer that also generates an uninstaller in Windows.

 

# -*- mode: python -*-


import os
from kivy_deps import sdl2, glew

spec_root = os.path.abspath(SPECPATH)
block_cipher =
None
app_name = 'Your App Name'
win_icon = '../Images/your_icon.ico'

a = Analysis(['../main.py'],
            
pathex=[spec_root],
            
binaries=[],
            
datas=[('../*.kv', '.'),                   # Change these to match your project
                    (
'../Images/*.png', './Images')],
            
hiddenimports=['win32timezone'],
            
hookspath=[],
            
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,
          [],
         
exclude_binaries=True,
         
name=app_name,
         
debug=False,
         
bootloader_ignore_signals=False,
         
strip=False,
         
upx=False,
         
console=False,
         
icon=win_icon)
coll = COLLECT(exe,
               a.binaries,
               a.zipfiles,
               a.datas,
               *[Tree(p)
for p in (sdl2.dep_bins + glew.dep_bins)],
              
strip=False,
              
upx=False,
              
name=app_name)

--
You received this message because you are subscribed to the Google Groups "Kivy users support" group.
To unsubscribe from this group and stop receiving emails from it, send an email to kivy-users+...@googlegroups.com.
To view this discussion on the web visit https://groups.google.com/d/msgid/kivy-users/d07242ff-c5c9-4589-90ea-a194b15d945fn%40googlegroups.com.

 

WvdB63

unread,
Aug 9, 2021, 3:29:53 PM8/9/21
to Kivy users support
Hi Elliot,
Thanks for this answer which solved the problem.

Wim

Op maandag 9 augustus 2021 om 20:33:28 UTC+2 schreef ElliotG:
Reply all
Reply to author
Forward
0 new messages