我可以从Pyscripter内运行Kivy程序吗? [英] Can I run a Kivy program from within Pyscripter?

查看:231
本文介绍了我可以从Pyscripter内运行Kivy程序吗?的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我在Pyscripter中输入了这个代码:

  import kivy 

kivy.require( '1.7.2')

从kivy.app import App

来自kivy.uix.label import标签

class MyApp(App):

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

MyApp()。run()

然后按Run按钮(绿色三角形)。
我得到以下错误:

 导入错误:没有名为kivy 

我可以做些什么来使这项工作吗?



PS我知道我可以离开Pyscripter并使用kivy.bat,
,但我想使用Pyscripter中的调试功能。

解决方案

我认为这可能是因为kivy.bat真的设置并使用了安装了kivy的第二个python发行版。但是,pyscripter正在使用您正常的系统安装,该安装没有安装kivy模块。



您可以告诉pyscripter将kivy解释器与正确的环境设置。我不知道如何(我从未在Windows上尝试过),但是例如这个上一个问题是类似的,但是关于pycharm而不是pyscripter。我已经粘贴了下面的答案,其中一些具体涉及到pycharm,但类似的东西可能适用于pyscripter。


安装并打开PyCharm

 如果您已经安装并已打开项目,请单击文件 - >设置(Ctrl + Alt + S)。 (如果没有,创建一个新项目,并且

单击解释器旁边的...并跳过步骤2)
在项目设置下,单击项目解释器 - > Python解释器
单击小绿色+并选择本地(您也可以从此列表中设置一个解释器到您安装的python)
将其指向..\Kivy\Python\python.exe并单击确定(Mine的路径是c:\Program文件(x86)\Kivy\Python\python.exe,因为那里是
我解压缩了kivy zip文件)



我还在这里附加了一个settings.jar文件
https://groups.google.com/forum/#!topic/kivy-users/xTpib2C8r_A 。这个
是kv语言的定义。它不完整,但它有很多帮助。
单击文件 - >导入 - >选择settings.jar文件。只有FileTypes将
打勾。导入这个,你将在文件 - >设置 - IDE设置 - >文件类型下有kv语言文件定义


打开一个kv文件以查看颜色差异以及
自动完成小部件是类型1属性是类型2所有事件
(on_something)是类型3类型4只是自己和根。



- 这是PyCharm的所有,其余的是Windows 7的具体内容。 - 1.打开命令提示符并浏览到您的..\Kivy\Python\lib文件夹2.键入mklink / D kivy..\Kivy\kivy\kivy(Mines line is mklink / D kivyc:\程序文件(x86)\Kivy\kivy\kivy)这将设置一个
符号链接,以便您的所有kivy python文件被读取,并且
定义被包括在内,以获得自动填充



现在我们需要设置环境变量。您可以在PyCharm中的每个
项目中执行此操作,但也可以在Windows中执行此操作,因此
只需要每次选择python解释器单击开始和
类型envir选择第二个。 (系统变量)(您还可以通过Win + PauseBreak->单击高级系统设置
)单击
环境变量



现在添加这些(再次指出,只要你有你的kivy
文件夹,你也可以在kivy.bat文件中找到所有这些,只需找到
并用你的路径替换变量)



GST_PLUGIN_PATH c:\程序文件
(x86)\Kivy\gstreamer\lib\gstreamer-0.10



GST_REGISTRY c:\程序文件(x86)\Kivy\gstreamer\registry.bin



路径c:\程序文件(x86)\\ \\ Kivy; c:\Program文件
(x86)\Kivy\Python; c:\Program文件(x86)\Kivy\gstreamer\bin; c:\Program
文件(x86)\Kivy\MinGW\bin; c:\Program文件(x86)\Kivy; c:\Program
文件(x86)\Kivy\Python; c: \程序文件
(x86)\Kivy\gstreamer\bi n; c:\程序文件(x86)\Kivy\kivy;%PATH%



重新启动计算机。 (对于要加载的环境变量)



现在,当您打开kivy项目时,只需选择您先前设置的Kivy解释器
,然后滚动你的叔叔。


您还可以尝试在现有的python安装中安装kivy。 kivy网站上有这样的说明: here 。我没有尝试过,可能会有一些棘手的一点。


I've entered this code in Pyscripter:

import kivy

kivy.require('1.7.2')

from kivy.app import App

from kivy.uix.label import Label

class MyApp(App):

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

MyApp().run()

I then press the Run button (the green triangle). I get the following error:

Import error: No module named kivy

What can I do to make this work?

P.S. I know I can leave Pyscripter and use kivy.bat, but I would like to use the debugging capabilities within Pyscripter.

解决方案

I think this is probably because kivy.bat really sets up and uses a second python distribution that has kivy installed. However, pyscripter is using your normal system installation, which does not have the kivy module installed.

You can probably tell pyscripter to use the kivy interpreter with the right environment set up. I don't know how exactly (I haven't ever tried on windows), but for instance this previous question is similar but about pycharm rather than pyscripter. I have pasted the answer below, some of it relates specifically to pycharm but something similar will probably work for pyscripter.

Install and open PyCharm

If you already had it installed and have a project open, click File -> Settings (Ctrl + Alt + S). (If not, create a new project, and

click the '...' next to interpreter, and skip step 2) Under Project Settings, click Project Interpreter -> Python Interpreters Click the little green + and select local (You can also set up an interpreter to your installed python from this list) Point it to ..\Kivy\Python\python.exe and click ok (Mine's path was c:\Program files (x86)\Kivy\Python\python.exe since that is where I unzipped the kivy zip file to)

I have also attached a settings.jar file here https://groups.google.com/forum/#!topic/kivy-users/xTpib2C8r_A. This is the kv language definition. Its not complete, but it helps a lot. Click File->Import-> Select the settings.jar file. Only FileTypes will be ticked. import this and you will have "kv language file" definition under File->Settings-IDE Settings->File Types

Open a kv file to see the differentiation in colours, as well as autocomplete Widgets are type 1 Properties are type 2 all events (on_something) are type 3 type 4 is just self and root.

-- That is all for PyCharm, the rest is Windows 7 specific things. -- 1. open a command prompt and browse to your ..\Kivy\Python\lib folder 2. type mklink /D kivy "..\Kivy\kivy\kivy" (Mines line was mklink /D kivy "c:\Program files (x86)\Kivy\kivy\kivy") This will set up a symlink so that your all your kivy python files are read and their definitions are included, in order to get autocomplete

Now we need to set up the environment variables. You could do this per project inside PyCharm, but might as well do it in windows, so you only need to select the python interpreter each time Click start and type envir Select the second one. (System variables) ( You could also get here with Win+PauseBreak-> Click Advanced system settings) Click Environment variables

Now add these (Once again, just point to wherever you have your kivy folder. You can also find all these in the kivy.bat file, just find and replace the variables with your path)

GST_PLUGIN_PATH c:\Program Files (x86)\Kivy\gstreamer\lib\gstreamer-0.10

GST_REGISTRY c:\Program Files (x86)\Kivy\gstreamer\registry.bin

PATH c:\Program Files (x86)\Kivy;c:\Program Files (x86)\Kivy\Python;c:\Program Files (x86)\Kivy\gstreamer\bin;c:\Program Files (x86)\Kivy\MinGW\bin;c:\Program Files (x86)\Kivy;c:\Program Files (x86)\Kivy\Python;c:\Program Files (x86)\Kivy\gstreamer\bin;c:\Program Files (x86)\Kivy\kivy;%PATH%

Restart your machine. (For the environment variables to load)

Now when you open your kivy project, just select the Kivy interpreter you set up earlier, and bobs your uncle.

You can also try to install kivy in your existing python installation. The kivy website has instructions for this here. I haven't tried this, and there may be some tricky bits.

这篇关于我可以从Pyscripter内运行Kivy程序吗?的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆