Undefined variable from import when using wxPython in pydev

前端 未结 6 1649
故里飘歌
故里飘歌 2020-12-09 17:03

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 i

相关标签:
6条回答
  • 2020-12-09 17:44

    PyDev finds the references when you setup the interpreter in

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

    If wxPython was not in your site-packages directory when you first setup the interpreter, then the references to the wx objects and names will not be known to the editor lookup function. To fix this, remove the interpreter from

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

    and then select new. Re-add the python installation again and press apply. At this time, Pydev will import all of the site-package objects again and should populate the lookup dictionary. You'll want to restart Eclipse for changes to take place.

    0 讨论(0)
  • 2020-12-09 17:47
    #import  wx 
    from    wx import wx #@UnresolvedImport
    

    will fix.

    0 讨论(0)
  • 2020-12-09 17:50

    Use CTRL+1 key combination on error text and add #@UndefinedVariable or #@UnresolvedImport in the end of corresponding lines with errors, it will remove these warnings temporary. See this answer: How do I fix PyDev "Undefined variable from import" errors?

    0 讨论(0)
  • 2020-12-09 17:54

    Some of the newer versions of pydev (circa January 2010) have a hard time tracking down imported names. It's probably nothing.

    If this is still occurring, report the bug to aptana appcelerator, though no doubt they already know about it.

    I get this problem when working with packages I've just recently downloaded, and eventually the errors go away. My most recent problem was after downloading pygame (circa January 2010).

    Edit

    I've amended my answer above since people are downvoting it, and I'm assuming it's because the information is stale, or because appcelerator bought aptana. I have not used pydev with Eclipse for nearly 2 years and the situation may be different now.

    0 讨论(0)
  • 2020-12-09 17:55

    Try

    wx = wx

    Don't ask why. This approach (that I found when trying to break the problem in smaller parts) just seems to remove the wx undefined variables problem.

    0 讨论(0)
  • 2020-12-09 17:59

    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:\Python26\lib\site-packages\wx-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.

    0 讨论(0)
提交回复
热议问题