Reputation: 412
I have Eclipse Version: 4.2.1 and PyDev version 2.7.1 installed on my 64-bit Ubuntu. I am using Python 2.7 and I have this problem with Eclipse that it doesn't recognize my un-imported methods. For example if I write a code like this:
def main():
myfiles = os.listdir('src')
if __name__ == '__main__':
main()
print'done!'
I get this error:
Traceback (most recent call last):
File "tset.py", line 5, in <module>
main()
File "tset.py", line 2, in main
myfiles = os.listdir('src')
NameError: global name 'os' is not defined
which is a pretty obvious error because I didn't write "import os" at the beginning of my code. My problem is that Eclipse doesn't highlight these errors for me anymore. Either I have to find them by myself or I will find out about them when I run my code. My Eclipse was working fine before but I don't know what did I change that this happened.
I should also mention that I have "lib" folder in my project and in that folder I have a few of my own modules and I have added the "lib" folder to PYTHONPATH of my project. And the code that I am running is in another folder named "test" and that's not in the PYTHONPATH.
Upvotes: 2
Views: 1698
Reputation: 19969
In addition to the answer by @183.amir, if one of your apps is symlinked (not an actual directory), you need to add it to PYTHONPATH separately (with the steps described above).
Upvotes: 1
Reputation: 412
The problem was that my code was in a folder like this:
/MyProject/src/test/test.py
But the "src" folder was not in the PYTHONPATH. That is why Eclipse was not recognizing them as a source code and was not analyzing them.
To fix this go to:
Eclipse -> Project -> Properties -> PyDev-PYTHONPATH -> Source Folders
and add "/MyProject/src" to source folders. (I only had "/MyProject/src/lib" in my source folders)
Upvotes: 3