Trouble with code

Joined
Mar 3, 2023
Messages
1
Reaction score
0
yo so im trying to do a mobile application using python this is my code: import kivy
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy.garden.folium import MapView, Marker

import folium

class MapScreen(BoxLayout):
def __init__(self, **kwargs):
super().__init__(**kwargs)

# Create a Folium map
m = folium.Map(location=[51.5074, -0.1278], zoom_start=13)

# Add a marker to the map
marker = folium.Marker(location=[51.5074, -0.1278], popup='London')
marker.add_to(m)

# Convert the Folium map to a Kivy widget
self.mapview = MapView(zoom=13, lat=51.5074, lon=-0.1278)
self.mapview.add_tile_layer('http://{s}.tile.osm.org/{z}/{x}/{y}.png')
self.mapview.add_marker(Marker(lat=51.5074, lon=-0.1278, popup='London'))

# Add the Kivy widget to the screen
self.add_widget(self.mapview)

class MapApp(App):
def build(self):
return MapScreen()

if __name__ == '__main__':
MapApp().run()

but i get this result:
Traceback (most recent call last):
File "C:\Users\nikor\Desktop\map_app.py", line 4, in <module>
from kivy.garden.folium import MapView, Marker
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 672, in _load_unlocked
File "<frozen importlib._bootstrap>", line 640, in _load_backward_compatible
KeyError: 'kivy.garden.folium' Traceback (most recent call last):
File "C:\Users\nikor\Desktop\map_app.py", line 4, in <module>
from kivy.garden.folium import MapView, Marker
File "<frozen importlib._bootstrap>", line 1027, in _find_and_load
File "<frozen importlib._bootstrap>", line 1006, in _find_and_load_unlocked
File "<frozen importlib._bootstrap>", line 672, in _load_unlocked
File "<frozen importlib._bootstrap>", line 640, in _load_backward_compatible
KeyError: 'kivy.garden.folium'

any ideas ?
 
Joined
Mar 5, 2023
Messages
8
Reaction score
3
It looks like you are encountering an error related to the `kivy.garden.folium` package. The `KeyError` suggests that this package cannot be found or loaded properly.

To resolve this issue, you can try installing the `kivy-garden` package and then installing `folium` through `kivy-garden`. You can do this by running the following commands in your command prompt or terminal:

Code:
pip install kivy-garden
garden install folium

After these packages are installed, try running your code again and see if the issue is resolved.
 
Joined
Mar 15, 2023
Messages
5
Reaction score
0
The error message indicates that there is a KeyError with the message 'kivy.garden.folium'. This error occurs because the kivy.garden.folium package is not installed on your system.

To fix this error, you need to install the kivy-garden package and then install the folium package using kivy-garden:

  1. Install kivy-garden by running the following command in your terminal:
    Code:
    pip install kivy-garden
  2. Install folium using kivy-garden by running the following command:
    Code:
    garden install folium

Once you have installed both packages, you should be able to run your code without any errors.
 

Ask a Question

Want to reply to this thread or ask your own question?

You'll need to choose a username for the site, which only take a couple of moments. After that, you can post your question and our members will help you out.

Ask a Question

Members online

No members online now.

Forum statistics

Threads
473,769
Messages
2,569,578
Members
45,052
Latest member
LucyCarper

Latest Threads

Top