Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
353 views
in Technique[技术] by (71.8m points)

python - Trying to run KIVY, for the first time

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!

running "python.exe C:Python27hello.py" 

Traceback (most recent call last):
  File "C:Python27hello.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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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!


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...