Python Forum
Error when running kivy on python - Printable Version

+- Python Forum (https://python-forum.io)
+-- Forum: Python Coding (https://python-forum.io/forum-7.html)
+--- Forum: General Coding Help (https://python-forum.io/forum-8.html)
+--- Thread: Error when running kivy on python (/thread-40185.html)



Error when running kivy on python - janeik - Jun-16-2023

desktop pc, win 10 , python 3.11, kivy 2.2

Hello. I am trying to run this code to confirm setup before I dive into python and kivy trying to achieve my goal.
The code is from an slightly changed example, viewing a youtube video.
The result should show a map beeing able to zoom and a position on map.
Any wizzards out there who can help me code to work?
Is this error due to wrong setup of python (no indication during setup of erroor),or programming?
Thank you for any guideance.

Here is the code:
import kivy
kivy.require('2.2.0') # replace with your current kivy version !

from kivymd.app import MDAppApp
from kivy_garden.mapview import MapView


class MyApp(MDApp):

    def build(self):
    mapview = MapView(zoom=10, Lat=36, Lon=-115)
        return mapview
        
    MapViewApp().run()[error]IndentationError: expected an indented block after function definition on line 10[output]None observed[/output][/error]



RE: Error when running kivy on python - menator01 - Jun-16-2023

Check your indent on the build function


RE: Error when running kivy on python - janeik - Jun-16-2023

(Jun-16-2023, 01:34 PM)menator01 Wrote: Check your indent on the build function
Thanks. I arranged the block elements at, hopefully, right spot. There is still something to correct according to this errormsg(at bottom). Any hints? Thank You.
Error:
C:\Users\jan-e>python d:\mapfiler\map.py [INFO ] [Logger ] Record log in C:\Users\jan-e\.kivy\logs\kivy_23-06-16_3.txt [INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.3.3 [INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.1 [INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.6.0 [INFO ] [Kivy ] v2.2.0 [INFO ] [Kivy ] Installed at "D:\Python311\Lib\site-packages\kivy\__init__.py" [INFO ] [Python ] v3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] [INFO ] [Python ] Interpreter at "D:\Python311\python.exe" [INFO ] [Logger ] Purge log fired. Processing... [INFO ] [Logger ] Purge finished! Traceback (most recent call last): File "d:\mapfiler\map.py", line 4, in <module> from kivymd.app import MDApp ModuleNotFoundError: No module named 'kivymd'



RE: Error when running kivy on python - deanhystad - Jun-16-2023

The error says it cannot find a module named "kivymd". Did you install kivymd? Installing kivy does not install kivymd.

When you type "pip list" in a command shell, does it list kivymd?


RE: Error when running kivy on python - janeik - Jun-16-2023

(Jun-16-2023, 04:59 PM)deanhystad Wrote: The error says it cannot find a module named "kivymd". Did you install kivymd? Installing kivy does not install kivymd.

When you type "pip list" in a command shell, does it list kivymd?

No it wasnt listed. so I installed it ver.1.1.1
Running this code
from kivymd.app import MDApp
from kivy_garden.mapview import MapView
 
 
class MyApp(MDApp):
 
     def build(self):
              mapview = MapView(zoom=10, Lat=36, Lon=-115)
              return mapview                                                         
    MapViewApp().run()
gives new error:
Error:
File "d:\mapfiler\map.py", line 16 MapViewApp().run() ^ IndentationError: unindent does not match any outer indentation level



RE: Error when running kivy on python - janeik - Jun-16-2023

(Jun-16-2023, 04:59 PM)deanhystad Wrote: The error says it cannot find a module named "kivymd". Did you install kivymd? Installing kivy does not install kivymd.

When you type "pip list" in a command shell, does it list kivymd?

I tried to change code to:
[python][


from kivymd.app import MDApp
from kivy_garden.mapview import MapView


class MyApp(MDApp):

def build(self):
mapview = MapView(zoom=10, Lat=36, Lon=-115)
return mapview
MyApp().run()
/python]

Got this error:
Error:
C:\Users\jan-e>python d:\mapfiler\map.py [INFO ] [Logger ] Record log in C:\Users\jan-e\.kivy\logs\kivy_23-06-16_21.txt [INFO ] [deps ] Successfully imported "kivy_deps.angle" 0.3.3 [INFO ] [deps ] Successfully imported "kivy_deps.glew" 0.3.1 [INFO ] [deps ] Successfully imported "kivy_deps.sdl2" 0.6.0 [INFO ] [Kivy ] v2.2.0 [INFO ] [Kivy ] Installed at "D:\Python311\Lib\site-packages\kivy\__init__.py" [INFO ] [Python ] v3.11.4 (tags/v3.11.4:d2340ef, Jun 7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)] [INFO ] [Python ] Interpreter at "D:\Python311\python.exe" [INFO ] [Logger ] Purge log fired. Processing... [INFO ] [Logger ] Purge finished! [INFO ] [KivyMD ] 1.1.1, git-Unknown, 2023-06-16 (installed at "D:\Python311\Lib\site-packages\kivymd\__init__.py") [INFO ] [Factory ] 190 symbols loaded [INFO ] [Image ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored) [INFO ] [Text ] Provider: sdl2 [INFO ] [Window ] Provider: sdl2 [INFO ] [GL ] Using the "OpenGL" graphics system [INFO ] [GL ] GLEW initialization succeeded [INFO ] [GL ] Backend used <glew> [INFO ] [GL ] OpenGL version <b'4.6.0 NVIDIA 531.79'> [INFO ] [GL ] OpenGL vendor <b'NVIDIA Corporation'> [INFO ] [GL ] OpenGL renderer <b'NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2'> [INFO ] [GL ] OpenGL parsed version: 4, 6 [INFO ] [GL ] Shading version <b'4.60 NVIDIA'> [INFO ] [GL ] Texture max size <32768> [INFO ] [GL ] Texture max units <32> [INFO ] [Window ] auto add sdl2 input provider [INFO ] [Window ] virtual keyboard not allowed, single mode, not docked Traceback (most recent call last): File "kivy\_event.pyx", line 235, in kivy._event.EventDispatcher.__init__ TypeError: object.__init__() takes exactly one argument (the instance to initialize) The above exception was the direct cause of the following exception: Traceback (most recent call last): File "d:\mapfiler\map.py", line 16, in <module> MyApp().run() File "D:\Python311\Lib\site-packages\kivy\app.py", line 955, in run self._run_prepare() File "D:\Python311\Lib\site-packages\kivy\app.py", line 925, in _run_prepare root = self.build() ^^^^^^^^^^^^ File "d:\mapfiler\map.py", line 14, in build mapview = MapView(zoom=10, Lat=36, Lon=-115) ^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^^ File "D:\Python311\Lib\site-packages\kivy_garden\mapview\view.py", line 560, in __init__ super().__init__(**kwargs) File "D:\Python311\Lib\site-packages\kivy\uix\widget.py", line 357, in __init__ super(Widget, self).__init__(**kwargs) File "kivy\_event.pyx", line 238, in kivy._event.EventDispatcher.__init__ TypeError: Properties ['Lat', 'Lon'] passed to __init__ may not be existing property names. Valid properties are ['_pause', '_zoom', 'animation_duration', 'background_color', 'bbox', 'cache_dir', 'center', 'center_x', 'center_y', 'children', 'cls', 'delta_x', 'delta_y', 'disabled', 'double_tap_zoom', 'height', 'ids', 'lat', 'lon', 'map_source', 'motion_filter', 'opacity', 'parent', 'pause_on_action', 'pos', 'pos_hint', 'right', 'size', 'size_hint', 'size_hint_max', 'size_hint_max_x', 'size_hint_max_y', 'size_hint_min', 'size_hint_min_x', 'size_hint_min_y', 'size_hint_x', 'size_hint_y', 'snap_to_zoom', 'top', 'width', 'x', 'y', 'zoom'] C:\Users\jan-e>



RE: Error when running kivy on python - janeik - Jun-16-2023

No errors, but sadly, no map seen on screen.

from kivy.config import Config
Config.set('kivy','keyboard_mode','systemanddock')

from kivymd.app import MDApp
from kivy_garden.mapview import MapView
 
 
class MyApp(MDApp):
 
     def build(self):
              mapview = MapView(zoom=10, Lat=36, Lon=-115)
              return mapview
              if __name__ == '__main__':
                 MyApp().run()[output]C:\Users\jan-e>python d:\mapfiler\main.py
[INFO   ] [Logger      ] Record log in C:\Users\jan-e\.kivy\logs\kivy_23-06-16_29.txt
[INFO   ] [deps        ] Successfully imported "kivy_deps.angle" 0.3.3
[INFO   ] [deps        ] Successfully imported "kivy_deps.glew" 0.3.1
[INFO   ] [deps        ] Successfully imported "kivy_deps.sdl2" 0.6.0
[INFO   ] [Kivy        ] v2.2.0
[INFO   ] [Kivy        ] Installed at "D:\Python311\Lib\site-packages\kivy\__init__.py"
[INFO   ] [Python      ] v3.11.4 (tags/v3.11.4:d2340ef, Jun  7 2023, 05:45:37) [MSC v.1934 64 bit (AMD64)]
[INFO   ] [Python      ] Interpreter at "D:\Python311\python.exe"
[INFO   ] [Logger      ] Purge log fired. Processing...
[INFO   ] [Logger      ] Purge finished!
[INFO   ] [KivyMD      ] 1.1.1, git-Unknown, 2023-06-16 (installed at "D:\Python311\Lib\site-packages\kivymd\__init__.py")
[INFO   ] [Factory     ] 190 symbols loaded
[INFO   ] [Image       ] Providers: img_tex, img_dds, img_sdl2, img_pil (img_ffpyplayer ignored)
[INFO   ] [Text        ] Provider: sdl2
[INFO   ] [Window      ] Provider: sdl2
[INFO   ] [GL          ] Using the "OpenGL" graphics system
[INFO   ] [GL          ] GLEW initialization succeeded
[INFO   ] [GL          ] Backend used <glew>
[INFO   ] [GL          ] OpenGL version <b'4.6.0 NVIDIA 531.79'>
[INFO   ] [GL          ] OpenGL vendor <b'NVIDIA Corporation'>
[INFO   ] [GL          ] OpenGL renderer <b'NVIDIA GeForce GTX 1070 Ti/PCIe/SSE2'>
[INFO   ] [GL          ] OpenGL parsed version: 4, 6
[INFO   ] [GL          ] Shading version <b'4.60 NVIDIA'>
[INFO   ] [GL          ] Texture max size <32768>
[INFO   ] [GL          ] Texture max units <32>
[INFO   ] [Window      ] auto add sdl2 input provider
[INFO   ] [Window      ] virtual keyboard allowed, single mode, docked[/output]



RE: Error when running kivy on python - deanhystad - Jun-16-2023

More indentation errors.

In Python, indenting serves the same purpose as {} in C. It creates blocks of code. If your code was written using {} for blocking, it would look like this:
from kivy.config import Config
Config.set('kivy','keyboard_mode','systemanddock')
 
from kivymd.app import MDApp
from kivy_garden.mapview import MapView
  
  
class MyApp(MDApp):
{
     def build(self):
     {
              mapview = MapView(zoom=10, Lat=36, Lon=-115)
              return mapview
              if __name__ == '__main__':
              {
                 MyApp().run()
              }
     }
}
Maybe this makes it easier to see that your code does not make any MyApp objects. The only code that makes a MyApp object is deeply embedded in the build method of the MyApp class.

Also, your indenting is all over the place. Convention is every indent level is 4 spaces deeper than the previous level.

Maybe you should work through some kivy totorials. You cannot have success if you don't understand your tools.


RE: Error when running kivy on python - janeik - Jun-16-2023

(Jun-16-2023, 09:54 PM)deanhystad Wrote: More indentation errors.

In Python, indenting serves the same purpose as {} in C. It creates blocks of code. If your code was written using {} for blocking, it would look like this:
from kivy.config import Config
Config.set('kivy','keyboard_mode','systemanddock')
 
from kivymd.app import MDApp
from kivy_garden.mapview import MapView
  
  
class MyApp(MDApp):
{
     def build(self):
     {
              mapview = MapView(zoom=10, Lat=36, Lon=-115)
              return mapview
              if __name__ == '__main__':
              {
                 MyApp().run()
              }
     }
}
Maybe this makes it easier to see that your code does not make any MyApp objects. The only code that makes a MyApp object is deeply embedded in the build method of the MyApp class.

Also, your indenting is all over the place. Convention is every indent level is 4 spaces deeper than the previous level.

Maybe you should work through some kivy totorials. You cannot have success if you don't understand your tools.

Thanks for input. You are right. I just thought I should try an example from a youtube video before I dived into more suitable beginner levels. Was not even aware of the indenting. I will start with Python then Kivy and hopefully end up handling maps, Thanks for help and see You later. Regards