I've got a Python project using PyDev in Eclipse, and PyDev keeps generating false errors for my code. I have a module settings
that defines a settings
object. I import that in module b
and assign an attribute with:
from settings import settings
settings.main = object()
In some of my code--but not all of it, statements like:
from settings import settings
print settings.main
... generate "Undefined variable from import: main" messages in the Eclipse code error pane, even though the code runs without a problem. How can I correct these?
Right click in the project explorer on whichever module is giving errors. Go to PyDev->Remove Error Markers.
The post marked as answer gives a workaround, not a solution.
This solution works for me:
Window - Preferences - PyDev - Interpreters - Python Interpreter
Forced builtins
tabNew...
multiprocessing
in my case) and clickOK
Not only will the error messages disappear, the module members will also be recognized.
I'm using opencv which relies on binaries etc so I have scripts where every other line has this silly error. Python is a dynamic language so such occasions shouldn't be considered errors.
I removed these errors altogether by going to:
Window -> Preferences -> PyDev -> Editor -> Code Analysis -> Undefined -> Undefined Variable From Import -> Ignore
And that's that.
It may also be, Window -> Preferences -> PyDev -> Editor -> Code Analysis -> Imports -> Import not found -> Ignore
I had the same problem. I am using Python and Eclipse on Windows. The code was running just fine, but eclipse show errors everywhere. After I changed the name of the folder 'Lib' to 'lib' (C:\Python27\lib), the problem was solved. It seems that if the capitalization of the letters doesn't match the one in the configuration file, this will sometimes cause problems (but it seems like not always, because the error checking was fine for long time before the problems suddenly appeared for no obvious reason).
My answer doesn't contribute anything new, just a concrete example I encountered.
PyDev showed the error message "Undefined variable from import: get_default_root_window()"
In the python shell you can see that this is a 'built-in' module as mentioned in a answer above:
Now under Window->Preferences->PyDev->Interpreters->Python Interpreter, I selected the tab 'Forced Builtins' and added 'gtk.gdk' to the list.
Now the error message didn't show anymore.
It is possible you just need to re-configure your python path within Eclipse. See my answer to a similar question.