John Doe John Doe - 6 months ago 66
Python Question

Python Kivy: unable to import main main

While reading the book, Creating Kivy apps with Python, it says to

"Next, update the imports in weather.kv to import this main module instead of the
ListItemButton class; see Example 3-7.
Example 3-7. Importing a custom class from main
#: import main main
#: import ListAdapter kivy.adapters.listadapter.ListAdapter"

which is supposed to be put in the .kv file for running. However, I get the following error:

File "/home/peter-brown/", line 58, in <module>
File "/usr/lib/python2.7/dist-packages/kivy/", line 797, in run
File "/usr/lib/python2.7/dist-packages/kivy/", line 594, in load_kv
root = Builder.load_file(rfilename)
File "/usr/lib/python2.7/dist-packages/kivy/", line 1749, in load_file
return self.load_string(data, **kwargs)
File "/usr/lib/python2.7/dist-packages/kivy/", line 1796, in load_string
parser = Parser(content=string, filename=fn)
File "/usr/lib/python2.7/dist-packages/kivy/", line 1185, in __init__
File "/usr/lib/python2.7/dist-packages/kivy/", line 1284, in parse
File "/usr/lib/python2.7/dist-packages/kivy/", line 1250, in execute_directives
mod = __import__('.'.join(package.split('.')[:-1]))
ValueError: Empty module name

TLDR: I'm getting an error that says the file is an emtpy module.
It seems to just be the 'main' file because taking it out causes the app to run smoothly.

Can someone explain why this is so? And what I can do to fix it?

Answer Source

Reference the Kv Language docs. That import is asking kivy to import the module main as main. If there is no module main, then kivy will raise an exception.

Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download