PyDev eclipse shows compile error red marks , but runs fine?
The following code is auto-generated by PyDev eclipse plugin, by choosing "new --> PyDev project" , new "PyDev Module", then choose "Unittest"
but on eclipse editor, it shows a red mark on "import unittest", saying that the module can not be imported. but this thing runs fine. I am using python 2.7 and eclipse 3.6
'''
Created on Dec 12, 2012
@author: yang
'''
import unittest
class Test(unittest.TestCase):
def testName(self):
pass
if __name__ == "__main__":
#import sys;sys.argv = ['', 'Test.testName']
unittest.main()
Solution is as follows: -
I removed these errors by going to:
Window -> Preferences -> PyDev -> Editor -> Code Analysis -> Undefined -> Undefined Variable From Import -> Ignore
And for import not found errors: -
It may also be,
Window -> Preferences -> PyDev -> Editor -> Code Analysis -> Imports -> Import not found -> Ignore
We forcibly remove these errors because python interpreter do not have a solution for this.
Let me know if you need further info on this.
You must be having a unittest.py file in your local system which is getting confused with unittest module. Rename your file and remove .pyc file along with this.
I can think of 2 reasons for this to fail:
The interpreter you have configured doesn't have the .py files, only .pyc files (for PyDev to work properly, you need to have an interpreter with the actual .py files).
The interpreter is not properly configured (ie: you created some virtualenv which references a parent env but the paths from the parent env were not properly added in the interpreter configuration) -- ie: the /Lib
which has the unittest
package (with unittest/__init__.py
) is not added to the PYTHONPATH at preferences > pydev > interpreters > python interpreter > select interpreter > libraries).
上一篇: Eclipse中没有识别Pydev