7

I'm trying to run kivy for the first time. Im using a default program.

from kivy.app import App
from kivy.uix.widget import Widget


class PongGame(Widget):
    pass


class PongApp(App):
    def build(self):
        return PongGame()


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

I get this error:

##################################
done bootstraping kivy...have fun!\n
running "python.exe C:\Python27\hello.py" \n
Traceback (most recent call last):
  File "C:\Python27\hello.py", line 1, in <module>
    from kivy.app import App
ImportError: No module named kivy.app
Press any key to continue . . .

A lot of people have raised the issue online, but no one has mentioned the right solution.

tshepang
  • 12,111
  • 21
  • 91
  • 136
user2834165
  • 383
  • 2
  • 7
  • 14

2 Answers2

14

UPDATE: based on the error you're getting—which you just pasted now, after my original response below—, you seem to be missing not only PyGame but Kivy itself. Go ahead and run pip install kivy.

But before you do that, I'd recommend you take a look at virtualenv and install all your Python packages specific to this project in a virtualenv created for that project. If you don't want that, you have to run sudo pip install kivy to install Kivy globally (assuming you're on OS X or Linux). On Windows, sudo should not be needed.

(Also, I'm sure the information below will be useful as well—since you don't even have Kivy, it must mean that you would have run into problems for not having PyGame either once would have installed Kivy.)

ORIGINAL ANSWER:

Short version:

You're missing PyGame, which is a dependency of Kivy.

Long version:

Since you didn't tell us what the error was, I went ahead and ran your code on my OS X 10.8 machine and got this:

$ python main.py
[INFO   ] Kivy v1.7.2
...
[CRITICAL] [Window      ] Unable to find any valuable Window provider at all!
[CRITICAL] [App         ] Unable to get a Window, abort.

googling that error landed me on http://kivy.org/docs/installation/troubleshooting-macosx.html.

So I went ahead and installed PyGame with the help of http://juliaelman.com/blog/2013/04/02/installing-pygame-on-osx-mountain-lion/; except I installed it in a virtualenv:

$ pip install hg+http://bitbucket.org/pygame/pygame

after that:

$ python yourcode.py
[INFO   ] Kivy v1.7.2
Purge log fired. Analysing...
Purge finished !
[INFO   ] [Logger      ] Record log in /Users/erik.allik/.kivy/logs/kivy_13-10-01_2.txt
[INFO   ] [Factory     ] 144 symbols loaded
[DEBUG  ] [Cache       ] register <kv.lang> with limit=None, timeout=Nones
[DEBUG  ] [Cache       ] register <kv.image> with limit=None, timeout=60s
...
[INFO   ] [OSC         ] using <multiprocessing> for socket
[DEBUG  ] [Base        ] Create provider from mouse
[INFO   ] [Base        ] Start application main loop

And I get a nice Kivy window popping up!

Erik Kaplun
  • 37,128
  • 15
  • 99
  • 111
  • Yeah, see the update at the beginning of my answer. Also, he pasted the error only after I had already posted my initial response; before that, it was impossible to tell what platform he was on. Also, I've already told him to install Kivy and how to do it, so I don't get the purpose of your comment. – Erik Kaplun Oct 01 '13 at 12:24
  • 1
    Yup Sorry. Forgot about it! Thanks! – user2834165 Oct 02 '13 at 17:33
  • @user2834165: that comment was directed at somebody else btw :) not sure what you should be sorry about! – Erik Kaplun Oct 04 '13 at 09:56
  • I'm getting this error: `Command "/usr/bin/python2.7 -c "import setuptools, tokenize;__file__='/tmp/pip-build-wrCJXo/kivy/setup.py';exec(compile(getattr(tokenize, 'open', open)(__file__).read().replace('\r\n', '\n'), __file__, 'exec'))" install --record /tmp/pip-R7LcPd-record/install-record.txt --single-version-externally-managed --compile" failed with error code 1 in /tmp/pip-build-wrCJXo/kivy` any suggestions? – Waiyl Karim Mar 31 '15 at 20:34
1

Maybe it's much more simple, it was for me. On kivy webpage provide a ‘portable package’ for windows OS so you don’t have to install anything “system” wide.

Then they explain how to make a shortcut to this ‘portable package’ on the Send-to menu. I've pasted the .bat instead of it's shortcut (never said i was smart) and I had (obviously) exacly the same error. If we can call it an error.

Hope it works for you too.