Ask Your Question

Kivy in ROS enviroment throws an error: ImportError: No module named app [closed]

asked 2016-04-19 13:31:28 -0500

robopo gravatar image

I would like to have an graphical interface in Kivy for my robot while ROS will works in background.

First will illustrate the project hierarchy.

ros_workscape                  <-catkin_wrokspace
    |--gui                <---catkin_package

I made a very simple interface in Kivy:

from import App
from kivy.uix.label import Label
from kivy.uix.button import Button
from kivy.uix.screenmanager import ScreenManager, Screen, SlideTransition
from kivy.uix.boxlayout import BoxLayout
import rospy
from gui.srv import LightsToggle

class MainMenuScreen(Screen):
    def __init__(self, **kwargs):
        super (MainMenuScreen, self).__init__(**kwargs)

layer = BoxLayout(orientation='vertical')
btn_lights = Button(text="Lights", size_hint_y=None, size_y=100)

    lights = Label(text="Lights: OFF", font_size='18dp', size_hint=(1, .3), halign='left')       


def lights_toggle(self, *args):
    rospy.wait_for_service('lights_toggle', timeout = 2.0)
    except rospy.ROSException:
        print("Failed. Is server running?")
    lights_toggle = rospy.ServiceProxy('lights_toggle', LightsToggle)
    response = lights_toggle()
    print ('Lights are :' + response)
except rospy.ServiceException, e:
    print ('Service call failed: ' + e)

class ControlPanelApp(App):     
    def build(self):
        screen_manager = ScreenManager(transition=SlideTransition())
        screen_1 = MainMenuScreen(name='menu')
        return screen_manager

def graphical_interface(cmd_q):

And this file is run by

from control_panel.graphical_interface import graphical_interface
if __name__ == '__main__':

Now the issue:
1) I run catkin_make in ros_workscape - done successfully.
2) source devel/setup.bash
3) rosrun gui ( ! roscore is already running)

The code is ok and it works.

It will fails with:

...somepath/ros_workspace/src/gui/control_panel/", line 6, in <module> from import App ImportError: No module named app

If I do not perform

source devel/setup.bash

then the Kivy works! But it fails on importing the


If I run the code without Kivy just ROS and with service (with source devel/setup.bash) it works as well.

I guess during the source devel/setup.bash is some system path or Python path overwritten but I can't figure it out.

edit retag flag offensive reopen merge delete

Closed for the following reason the question is answered, right answer was accepted by robopo
close date 2016-11-02 01:52:35.191902

1 Answer

Sort by » oldest newest most voted

answered 2016-04-24 00:55:46 -0500

robopo gravatar image

Finally I found it out. It's not overwritten, it's ok.

It's not a good idea to name your files, but even the folders should'nt have the name kivy. I made that mistake and I realized it before writting this question. So I renamed them.

That's why it works without doing the

source devel/setup.bash.

Meanwhile I in my catkin_workspace I ran the catkin_make. And it generated messages to following folder


And here was the folder called Kivy and from here it tries to import the Kivy and then it fails.

Be sure you rename everything and delete the rest (especially generated files). :-)

edit flag offensive delete link more

Question Tools

1 follower


Asked: 2016-04-19 13:31:28 -0500

Seen: 1,239 times

Last updated: Apr 24 '16