在eclipse pydev中未解决导入 [英] unresolved import in eclipse pydev

查看:122
本文介绍了在eclipse pydev中未解决导入的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我刚刚正确安装了谷歌gdata库为python(脚本实际运行正常)。我在日食中和pydev一起工作我导入了一个模块,但导入命令仍然是卷曲的下划线,您可以在屏幕截图中看到。





我添加了以下项目名称 - >属性,但它不起作用(尽管路径是确定正确):


解决方案

如果您有import语句,请执行以下操作:这样: import gdata.spreadsheet.service 然后你需要确保在 PYTHONPATH 有一个目录,其中包含 gdata 子目录(和 gdata 应该有电子表格子目录与 service.py 模块文件)



在你的情况下:如果你的 gdata 目录位于 site-packages 目录在python发行版,那么你需要确保 site-packages 是在PYTHONPATH(不是 site-packages / gdata / spreadsheet ,你试图放在那里。)



看看 http://docs.python.org/2/tutorial/modules.html 以及参考资料。



在PyDev中,您可以在两个地方修改PYTHONPATH的内容:




  • 窗口 - > PyDev - >口译 - Python

  • 在您使用的窗口中



我建议您先检查 site-packages 目录在您的窗口中 - > PyDev - >解释器 - Python设置 - >系统PYTHONPATH 。它应该在默认情况下,所以如果你没有改变它,它应该在那里(可能这就是你的应用程序的工作原理!)。



现在,从一些原因,PyDev在向 site-packages 添加新库之后经常会出现刷新有关可用库的信息的问题(例如,它使用该信息来检查是否应该在import语句中放错误标记)。



有几种方法强制刷新此信息。对我来说最可靠的就是通过以下方式删除python解释器: Window - > PyDev - >解释器 - Python - >删除,然后将其添加回同一个视图。然后重新扫描 site-packages 目录,PyDev会看到更新的库集,因此错误标记应该消失。



旁注:说实话,到目前为止,我还没有需要使用这个外部库视图。在99%的案例中,使用Interpreter设置中的网站包,因为应该放置Python外部库。


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.

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

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

解决方案

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.

这篇关于在eclipse pydev中未解决导入的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆