Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
552 views
in Technique[技术] by (71.8m points)

debugging - Can I run a Kivy program from within Pyscripter?

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

I've had the same trouble and I solved it out using a pyscripter's option in the 'Tools' menu called 'Edit Startup scripts' which's name says it all.

Everything you write there should be executed whenever pyscripter starts a python interpreter so it can be used among other things to do the same as 'kivy.bat' but inside pyscripter, I wrote the following startup script basing on info from here How to develop and run kivy apps on PyDev and it works fine for me.

# 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

Just change the kivy_path variable in the script so it fixes with the kivy package's path (folder containing kivy.bat) on your computer and you should be able to run your kivy apps just like when you open them with kiby.bat


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...