How do I handle an UnresolvedImport Eclipse (Python)

后端 未结 8 2417
悲&欢浪女
悲&欢浪女 2021-02-20 04:41

When I write import MySQLdb in Eclipse using the PyDev plugin, I get an unresolved import. However, the program runs without error. I can add an annotation to get

相关标签:
8条回答
  • 2021-02-20 05:28

    It sounds like MySQLdb is somewhere on your sys.path, but not on your Eclipse project's PYTHONPATH; in other words, Eclipse thinks you're going to get an import error at runtime because you haven't fully configured it. Google seems to say that you can alter this setting in Window->Preferences->Preferences->PyDev->Python Interpreter to include the path to your MySQLdb module.

    For some help figuring out where MySQLdb might be living on your system:

    1. Open an interactive interpreter,
    2. import MySQLdb
    3. If that succeeds, you can get a hint from: print MySQLdb.__file__; it may be the __init__ file in the package that you need to point the path at.
    0 讨论(0)
  • 2021-02-20 05:35

    cdleary above provided the reason two years ago, but this may be easier. Basically, one reinstalls the interpreter.

    1. Select Window - > Preferences -> PyDev -> Interpreter - Python
    2. Select the python interpreter in the upper pane
    3. Click on Remove
    4. Click on Auto Config
    5. Agree to everything.

    This works on Fedora 17 using the Eclipse 4.2.0 that came with the package management.

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