Python Unresolved import

来源:互联网 发布:阿里云部署java项目 编辑:程序博客网 时间:2024/06/04 18:31

 from selenium import webdriver 产生 Unresolved import: webdriver的问题。

网上查了一些资料,有人说是在包里面有和包名一样的py文件存在,try 后问题不能解决。

之后在 Stack Overflow 上发现了解决方案,

原文链接 http://stackoverflow.com/questions/2983088/unresolved-import-models/2983096

Even if Lib/site-packages is added to the PYTHONPATH, this problem may happen when using modules from egg packages installed using easy_install. The problem with those, and that might actually depend on the easy_install version, is that by default they don't get installed directly inside Lib/site-packages but rather under a folder containing the full package name and having the .egg suffix. For example: Lib/site-packages/django_celery-3.0.23-py2.7.egg

Each module coming from packages installed as above needs an individual entry in PYTHONPATH. If the packages are installed after PyDev has been installed on the system, the system PYTHONPATH needs to be updated in PyDev. That is done automatically by going to Window -> Preferences -> PyDev -> Select your intepreter -> in the python interpreters panel remove and re-add your current python interpreter (usually, this should be the python executable from the system). Then a PyDev restart (File -> Restart) should solve the "Unresolved import" errors.

作者的意思是问题是easy_install的问题,如果是在安装pydev之前安装的模块,应该不会有这个问题。如果是eclipse 安装了pydev之后用easy_insall安装的pydev,则需要重新配置一下pydev的interpreter 即可。

步骤:

1.删除原来的pydev的interpreter(windows->preference->pydev->interpreter)

2.把interpreter加进来,pydev会自动扫描python 下libs的所有模块,包括site-packages下的所有模块.


另:

pydev 官方解释:

http://pydev.org/manual_101_interpreter.html


0 0