John Doe John Doe - 1 year ago 130
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/kivytest.py", line 58, in <module>
DownloadApp().run()
File "/usr/lib/python2.7/dist-packages/kivy/app.py", line 797, in run
self.load_kv(filename=self.kv_file)
File "/usr/lib/python2.7/dist-packages/kivy/app.py", line 594, in load_kv
root = Builder.load_file(rfilename)
File "/usr/lib/python2.7/dist-packages/kivy/lang.py", line 1749, in load_file
return self.load_string(data, **kwargs)
File "/usr/lib/python2.7/dist-packages/kivy/lang.py", line 1796, in load_string
parser = Parser(content=string, filename=fn)
File "/usr/lib/python2.7/dist-packages/kivy/lang.py", line 1185, in __init__
self.parse(content)
File "/usr/lib/python2.7/dist-packages/kivy/lang.py", line 1284, in parse
self.execute_directives()
File "/usr/lib/python2.7/dist-packages/kivy/lang.py", line 1250, in execute_directives
mod = __import__('.'.join(package.split('.')[:-1]))
ValueError: Empty module name


TLDR: I'm getting an error that says the main.py 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