2013-12-17 53 views
0

我已經進入這個代碼Pyscripter:我可以在Pyscripter中運行Kivy程序嗎?

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() 

我,然後按運行按鈕(綠色三角形)。 我得到以下錯誤:

Import error: No module named kivy 

我能做些什麼,使這項工作?

P.S.我知道我可以離開Pyscripter並使用kivy.bat, 但我想使用Pyscripter中的調試功能。

回答

0

我想這可能是因爲kivy.bat確實設置並使用了第二個安裝了kivy的python發行版。但是,pyscripter正在使用正常的系統安裝,它沒有安裝kivy模塊。

您或許可以告訴pyscripter使用具有正確環境設置的kivy解釋器。我不知道如何(我沒有試過在Windows上),但例如this previous question是類似的,但關於pycharm而不是pyscripter。我粘貼了下面的答案,其中一些特別涉及到pycharm,但類似的東西可能適用於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.

您還可以嘗試在現有的python安裝中安裝kivy。 kivy網站有關於此here的說明。我還沒有嘗試過,可能會有一些棘手的問題。

3

我遇到過同樣的麻煩,我在'工具'菜單中使用pyscripter的選項解決了這個問題,該工具菜單名爲'Edit Startup scripts'。

你在那裏寫的所有東西都應該在pyscripter啓動一個python解釋器的時候執行,這樣它可以用來做'kivy.bat',但是在pyscripter裏面,我根據這裏的信息編寫了下面的啓動腳本How to develop and run kivy apps on PyDev,它對我來說很好。

# This startup script makes it possible to Pyscripter to work with the kivy package 

import sys 
import os 

kivy_path = 'C:/kivy' 
relative_modules_paths = ['/kivy', 
          '/Python/', 
          '/Python/Lib/', 
          '/Python/Lib/Site-packages/',] 

# tells the interpreter to look for python modules in the kivy modules' paths 
for relative_path in relative_modules_paths: 
    sys.path.append(kivy_path+relative_path) 

# sets some environment variables needed by kivy. Not permanent. 
os.environ['GST_PLUGIN_PATH'] = kivy_path+'/gstreamer/lib/gstreamer-0.10' 
os.environ['GST_REGISTRY'] = kivy_path+'gstreamer/registry.bin' 

kivy_environ_paths = '{kp};{kp}/Python;{kp}/gstreamer/bin;{kp}/MinGW/bin;' 
kivy_environ_paths = kivy_environ_paths.format(kp=kivy_path) 

os.environ['PATH'] = kivy_environ_paths 

# theorecally your environment variables won't be affected outside the 
# interpreter. You can still backup your environment variables if you 
# don't feel confident 

只要改變kivy_path變量的腳本,以便其與kivy包的路徑修復(含kivy.bat文件夾),您的計算機上,你應該能夠運行你的應用程序kivy就像當你打開他們kiby.bat

相關問題