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
226 views
in Technique[技术] by (71.8m points)

python - Undefined variable from import when using wxPython in pydev

I just downloaded wxPython, and was running some of the sample programs from here. However, on every line that uses a variable from wx.*, I get a "Undefined variable from import error"

For example, the following program generates five errors on lines 1,4,8, and two on line 5:

import wx
class MyFrame(wx.Frame):
    """ We simply derive a new class of Frame. """
    def __init__(self, parent, title):
        wx.Frame.__init__(self, parent, title=title, size=(200,100))
        self.control = wx.TextCtrl(self, style=wx.TE_MULTILINE)
        self.Show(True)
app = wx.App(False)
frame = MyFrame(None, 'Small editor')
app.MainLoop()

The program, however, compiles and runs perfectly. I haven't made any significant modifications to pydev or eclipse, and the wxPython install is fresh.

See Question&Answers more detail:os

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

1 Reply

0 votes
by (71.8m points)

This happened to me. I had installed PyDev and configured it and went on my merry way. A few months later, I installed wxPython and had this same problem. An easy way to fix is in eclipse:

Window -> Preferences -> Pydev -> Interpreter - Python

Just remove the default interpreter and add a new one (it can be the same one you had before). Pydev/Eclipse searches through your Python Installation directory and adds the correct paths to your PYTHONPATH. I restarted and all was well. I noticed it added

C:Python26libsite-packageswx-2.8-msw-unicode

So you could probably just add that to the PYTHONPATH instead of going through all the above, assuming that path is where this directory is installed.

By the way, I am using:

  1. Eclipse Helios
  2. Pydev 1.6.2.2010090812
  3. Python 2.6
  4. wxPython2.8-win32-unicode-2.8.11.0-py26

But I think this should be a pretty general solution to the problem.


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

...