No module named kivy.app

强颜欢笑 提交于 2020-05-31 07:21:25

问题


So I thought I'd toy around and try and learn Kivy, as it looks interesting. I have just started trying to get one of their examples working:

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

class MyPaintWidget(Widget):
    pass


class MyPaintApp(App):
        def build(self):
            return MyPaintWidget()

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

I get the following error:

C:\Kivy-1.8.0-py2.7-win32>python paint.py
Traceback (most recent call last):
  File "paint.py", line 1, in <module>
   from kivy.app import App
ImportError: No module named kivy.app

I have installed the latest version of Kivy. I see "app.py in the C:\Kivy-1.8.0-py2.7-win32\kivy\kivy folder.

Also, here is my PYTHONPATH:

>>> import sys
>>> for n in sys.path:
...     print n
...

C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\setuptools-2.0.1-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\pywin32-218-py2.7-win32.egg

C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\plyer-1.1.2-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\kivy_garden-0.1.1-py2.7.egg

C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages\requests-2.2.1-py2.7.egg
C:\Kivy-1.8.0-py2.7-win32\Python27\python27.zip
C:\Kivy-1.8.0-py2.7-win32\Python27\DLLs
C:\Kivy-1.8.0-py2.7-win32\Python27\lib
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\plat-win
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\lib-tk
C:\Kivy-1.8.0-py2.7-win32\Python27
C:\Kivy-1.8.0-py2.7-win32\Python27\lib\site-packages

Any help would be greatly appreciated. Thank you.


回答1:


So, I figured it out....I was not being very smart. I'm new to Kivy and I'll answer this for anyone else that is as green as I am. You can't just run this as a python program, doh.

Follow instructions [here] (http://kivy.org/docs/installation/installation-windows.html#start-a-kivy-application) and all will be right with the world.




回答2:


If you installed kivy using pip you need to add the packages to your environment. In Windows Command Prompt do

pip show kivy

~Take note of the Location of the module.

Next you can do 1 of two things.

  1. Configure any python files you write to refer to the location of your module with sys, use this tutorial for more info: https://kivy.org/docs/guide/environment.html
  2. Add the location you found above to your PATH (Windows): https://www.computerhope.com/issues/ch000549.htm

2 Worked for me.




回答3:


I ran into this error message when I named the script kivy.py, because python looks first in the current directory to fill the dependency, so it never sees the real kivy package.

Renaming the script fixed it for me.




回答4:


I know I am too late but I hope this will help others, I just did not run it from the command prompt, I opened the python code in my python shell and then pressed run 'F5' and it worked for me.



来源:https://stackoverflow.com/questions/28424188/no-module-named-kivy-app

标签
易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!