Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

How do I handle an UnresolvedImport Eclipse (Python)

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 the error to go away, but what is the right way to handle this?

How can I help Eclipse know that MySQLdb is there?

like image 597
Eric Wilson Avatar asked Mar 16 '10 02:03

Eric Wilson


3 Answers

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.
like image 125
cdleary Avatar answered Oct 21 '22 06:10

cdleary


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.

like image 21
PentheusLennuye Avatar answered Oct 21 '22 05:10

PentheusLennuye


Fixed this by doing two things:

1) Added MySQLdb egg to the PYTHONPATH under Window->Preferences->Preferences->PyDev->Python Interpreter.

C:\Python26\Lib\site-packages\MySQL_python-1.2.3c1-py2.6-win32.egg

2) Close and re-open the .py file that had the red x.

like image 6
LG_PDX Avatar answered Oct 21 '22 07:10

LG_PDX