Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
836 views
in Technique[技术] by (71.8m points)

unresolved import in eclipse pydev

I just properly installed the google gdata library for python (the script actually runs fine). I'm working with pydev in eclipse. I imported a module but the import command remains curly red underlined as you can see on the screenshot.

enter image description here

I added the following und ProjectName->Properties, but it does not work (although the path is definitly correct): enter image description here

What do I have to do such that the import is resovled correctly by eclipse?

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Answer

0 votes
by (71.8m points)

If you have import statement like this: import gdata.spreadsheet.service then you need to make sure that on PYTHONPATH there is a directory that contains gdata subdirectory (and gdata should have spreadsheet subdirectory with service.py module file).

In your case: if your gdata directory is in site-packages directory on python distribution, then you need to make sure that site-packages is on PYTHONPATH (not site-packages/gdata/spreadsheet that you were trying to put there).

Look at http://docs.python.org/2/tutorial/modules.html in "6.4 Packages" section for example and reference.

In PyDev you can modify the contents of PYTHONPATH in two places:

  • Window -> PyDev -> Interpreter - Python
  • In the window you used

I would suggest you to first check that site-packages directory is in your Window -> PyDev -> Interpreter - Python settings -> System PYTHONPATH. It should be there by default, so if you didn't change it, it should be present there (and probably that's why your application works!).

Now, from some reasons, PyDev often has problems with "refreshing" info about available libraries after adding a new library to site-packages (and it uses that info for example to check if it should put error marker on import statement).

There are a few ways to force the refresh of this info. The most reliable for me is just removing python interpreter by means of: Window -> PyDev -> Interpreter - Python -> Remove and then adding it back in the same view. Then the site-packages directory is rescanned and PyDev sees the updated set of libraries, so the error markers should disappear.

Side note: To be honest, so far I haven't ever need to use this External Libraries view. Having site-packages in Interpreter settings is fine enought for 99% of cases because there is where Python external libraries should be put.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome to OStack Knowledge Sharing Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...