简体   繁体   中英

How to Run Kivy Python programs on PC?

I Need to develop a program which runs on android using python. For this I heard kivy is the best module available. So I tried to install and run kivy on my pc. Mine is a windows 7 pc.

To achieve this I did the following :

  1. I downloaded the package file from https://pypi.python.org/pypi/Kivy#downloads
  2. Then I opened the package using win rar and pasted the contents to my python27/lib folder

Now when I type the following

    import kivy

The following message comes :

    [INFO              ] [Logger      ] Record log in      
    C:\Users\UserName\.kivy\logs\kivy_16-04-17_4.txt
    [INFO              ] [Kivy        ] v1.9.1
    [INFO              ] [Python      ] v2.7.4 (default, Apr  6 2013, 19:54:46) [MSC v.1500 32 bit (Intel)]

But when I try to run code as simple as this :

    import kivy
    from kivy.app import App
    from kivy.uix.label import Label

    class MyApp(App):

    def build(self):
        return Label(text='Hello world')


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

The following error message pops up.

    Traceback (most recent call last):
    File "D:/Python27/unfinished buisness/ufb.py", line 4, in <module>
     from kivy.app import App
    File "D:\Python27\lib\kivy\app.py", line 327, in <module>
     from kivy.uix.widget import Widget
    File "D:\Python27\lib\kivy\uix\widget.py", line 219, in <module>
     from kivy.graphics import (
    File "D:\Python27\lib\kivy\graphics\__init__.py", line 89, in <module>
     from kivy.graphics.instructions import Callback, Canvas, CanvasBase, \
    ImportError: DLL load failed: The specified module could not be found.

(But when I run this code on my android phone using Qpython { which comes with kivy already installed } it runs smoothly )

WHere am I going wrong ? Am I installing it wrongly ?

Is it even possible to run Kivy on pc ? or would it only run on android phones ?

Also I would like suggestion for any other modules which we can use to develop android applications using python.

You have installed kivy, but not properly. As it says, a DLL is missing - an important one and therefore it won't even run. Your code is ok, don't worry about that.

Kivy runs on each platform that Kivy supports, otherwise it'd be kind of... well, you know. Just don't install it with copy&paste and install it the proper way as it's mentioned here + don't forget to install libraries before you install kivy. For android you'd need to use vdi or it won't be releasable as APK(eg for google play).

QPython is a fantastic tool for a beginner, but the cons are that when you have large files, the editor has lags and also they don't use latest kivy afaik.

Also, use pip and spare yourself troubles with packages, because sometimes it can be painful. For this purpose I made KivyInstaller , because beginners sometimes have problems on windows - or mostly people who decide to learn coding with python and kivy first. Not a bad idea though, but they're not reading docs and just skip to word "install" and... here you go.

Recommended packages are basically at kivy github and are very useful if you are going to work on android. There are also modules especially for kivy that'll help you with developing.

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM