Kivy Garden
Kivy Garden is a project and command-line tool that centralizes user-contributed add-ons, called "flowers," for the Kivy framework. These "flowers" are typically distributed as separate PyPI packages under the `kivy_garden.*` namespace (e.g., `kivy_garden.mapview`). The `kivy-garden` tool facilitates the management and installation of both legacy and modern pip-installable Kivy extensions. It is currently at version 0.1.5 and provides utilities for Kivy developers to extend their applications with community-contributed widgets and tools.
Common errors
-
KeyError: 'kivy.garden.mapview' (or similar for other flowers) in Android build logs
cause The Kivy Garden 'flower' was not correctly included in the Android application package (APK), even if it runs fine on desktop. Buildozer did not detect or bundle the `kivy_garden.*` module.fixExplicitly add `kivy_garden.mapview` (or the name of your flower) to the `requirements` list in your `buildozer.spec` file. For example: `requirements = python3,kivy,kivy_garden.mapview`. -
ModuleNotFoundError: No module named 'kivy.garden.graph' (or similar for other flowers)
cause You are trying to import a Kivy Garden 'flower' using an outdated or incorrect import path, or the flower itself is not installed.fixEnsure the specific 'flower' is installed (e.g., `pip install kivy_garden.graph` or `garden install graph`). If it's a modern flower, use the import `from kivy_garden.graph import Graph`. If it's a legacy flower managed by the `garden` tool, ensure `kivy-garden` is installed and the `garden` command was used.
Warnings
- breaking Kivy 1.11.0 introduced a significant shift in the Kivy Garden structure. Newer 'flowers' are designed to be installed via `pip install kivy_garden.flower_name` and imported from `kivy_garden.*`. While the legacy `garden install flower_name` command still functions for older modules, new development and support primarily target the pip-installable package format.
- gotcha Kivy Garden 'flowers' are community-contributed and are not actively monitored or officially supported by the core Kivy developers. Their stability, maintenance, and adherence to Kivy's latest versions can vary significantly between individual 'flowers'.
- gotcha When packaging Kivy applications for mobile platforms (e.g., Android with Buildozer) that use Kivy Garden 'flowers', merely installing `kivy-garden` is insufficient. Each specific `kivy_garden.flower_name` package must be explicitly listed in the `requirements` section of your `buildozer.spec` file, or installed using `garden install --app flower_name` during the build process, to ensure it's bundled with your application.
Install
-
pip install kivy-garden -
pip install kivy_garden.mapview -
garden install graph
Imports
- MapView
from kivy.garden import mapview
from kivy_garden.mapview import MapView
Quickstart
from kivy.app import App
from kivy.uix.boxlayout import BoxLayout
from kivy_garden.mapview import MapView, MapMarker
from kivy.core.window import Window
# Ensure kivy_garden.mapview is installed: pip install kivy_garden.mapview
class MapApp(App):
def build(self):
Window.size = (800, 600)
box = BoxLayout(orientation='vertical')
# Initialize MapView with example coordinates
mapview = MapView(zoom=11, lat=50.6394, lon=3.057)
# Add a marker to the map
marker = MapMarker(lat=50.6394, lon=3.057, source="atlas://kivy_atlas/data/images/defaulttheme/star")
mapview.add_marker(marker)
box.add_widget(mapview)
return box
if __name__ == '__main__':
MapApp().run()