简体   繁体   English

如何在PC上运行Kivy Python程序?

[英]How to Run Kivy Python programs on PC?

I Need to develop a program which runs on android using python. 我需要开发一个使用python在android上运行的程序。 For this I heard kivy is the best module available. 为此,我听说kivy是最好的模块。 So I tried to install and run kivy on my pc. 所以我试图在我的电脑上安装并运行kivy。 Mine is a windows 7 pc. 我的是Windows 7 pc。

To achieve this I did the following : 为此,我做了以下工作:

  1. I downloaded the package file from https://pypi.python.org/pypi/Kivy#downloads 我从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 然后我使用win rar打开软件包,并将内容粘贴到我的python27 / lib文件夹中

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 ) (但是当我使用Qpython {在已安装kivy的手机上)在我的Android手机上运行此代码时,它运行起来很流畅)

WHere am I going wrong ? 我在哪里错? Am I installing it wrongly ? 我安装错误吗?

Is it even possible to run Kivy on pc ? 甚至有可能在PC上运行Kivy吗? or would it only run on android phones ? 还是只能在Android手机上运行?

Also I would like suggestion for any other modules which we can use to develop android applications using python. 我也想建议我们可以用来使用python开发android应用程序的任何其他模块。

You have installed kivy, but not properly. 您已经安装了kivy,但安装不正确。 As it says, a DLL is missing - an important one and therefore it won't even run. 就像说的那样,缺少DLL-一个重要的DLL,因此它甚至无法运行。 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. Kivy可以在Kivy支持的每个平台上运行,否则就有点……嗯,您知道的。 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. 只是不要使用复制和粘贴来安装它,并按照此处提到的那样正确安装它,并且在安装kivy之前不要忘记安装库。 For android you'd need to use vdi or it won't be releasable as APK(eg for google play). 对于android,您需要使用vdi否则它不会作为APK发布(例如,用于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. 对于初学者来说,QPython是一个很棒的工具,但是缺点是,当您有大文件时,编辑器会出现滞后,并且它们不会使用最新的kivy afaik。

Also, use pip and spare yourself troubles with packages, because sometimes it can be painful. 另外,请使用pip并避免使用软件包的麻烦,因为有时这会很痛苦。 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. 为此,我制作了KivyInstaller ,因为初学者有时在Windows上遇到问题-或大多数决定先学习python和kivy编码的人。 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. 推荐的软件包基本上在kivy github上 ,如果您要在android上工作,它们将非常有用。 There are also modules especially for kivy that'll help you with developing. 还有一些专门用于kivy的模块可以帮助您进行开发。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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