Pydev 说“未解决的导入”错误
嗯.. 有时,PyDev 会说“未解决的导入错误”。 在我的环境中
Python2.6.6 Eclipse3.7 PyDev2.2.2
错误是。
> Unresolved import: pycassa -> import pycassa Unresolved import:
> WebSocketHandler -> from geventwebsocket.handler import
> WebSocketHandler Unresolved import: tweepy -> import tweepy
有什么有用的信息吗?
hm..
Sometime, PyDev say "Unresolved import error".
In my environment
Python2.6.6 Eclipse3.7 PyDev2.2.2
Errors are.
> Unresolved import: pycassa -> import pycassa Unresolved import:
> WebSocketHandler -> from geventwebsocket.handler import
> WebSocketHandler Unresolved import: tweepy -> import tweepy
Is there any helpfull information?
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(11)
有同样的问题。最后,我通过在“首选项”>“删除旧解释器”中解决了该问题。 PyDev >解释器,并创建一个名为“python”的新解释器,它具有正确的路径。退出并重新打开 eclipse 后,pydev 找到了我的所有模块。
Had the same problem. In the end I was able to fix the problem by deleting my old interpreter in Preferences > PyDev > Interpreters, and creating a new interpreter called "python" which had the correct paths. After quitting and reopening eclipse, pydev found all my modules.
可能您的 PYTHONPATH 设置不正确(或者如果这些是解释器中的库,则可能您在配置后添加了它们)。
请参阅:http://pydev.org/manual_101_interpreter.html 以获取参考(请注意那里关于强制内置的部分因为这可能是你的情况)。
Probably your PYTHONPATH is not set properly (or if those are libraries in the interpreter, maybe you added them after configuring it).
See: http://pydev.org/manual_101_interpreter.html for references (note the part on forced builtins there as it might be your case).
如果找不到所需的模块,则会出现未解析的导入。在当前工作目录和 sys.path 中列出的目录中搜索模块。你的 python 找不到它出现的模块 pycassa 和 tweepy 。
可能想检查一下:http://klaith.wordpress。 com/2009/06/12/pydev-unresolved-import-errors/
You get an unresolved import if the required module cannot be found. Modules are searched for in the current working directory and the directories listed in sys.path. Your python cannot find the modules pycassa and tweepy it appears.
Might want to check this: http://klaith.wordpress.com/2009/06/12/pydev-unresolved-import-errors/
我通过重新创建解释器解决了。 pedev.org 上有一个指南:
感谢 Fabio Zadrozny 和 nicodjimenez。
I solved by recreate the interpreter. There is a guide at pedev.org:
Thanks for Fabio Zadrozny and nicodjimenez.
在 pydev 项目的属性中,有一个名为“PyDev - PYTHONPATH”的窗格,以及一个名为“External Libraries”的子窗格。您可以使用该窗格将源文件夹(任何具有 init.py 的文件夹)添加到路径中。然后,您的项目代码将能够从这些源文件夹导入模块。
检查这两个链接可能对您有帮助,
PyDev 和 Eclipse 未解决的导入问题
未解决的导入:模型
In the properties for your pydev project, there's a pane called "PyDev - PYTHONPATH", with a sub-pane called "External Libraries". You can add source folders (any folder that has an init.py) to the path using that pane. Your project code will then be able to import modules from those source folders.
Check this two links it may be helps to you,
Unresolved Import Issues with PyDev and Eclipse
Unresolved import: models
我以前也遇到过类似的问题。我通过以下步骤解决了问题:
1)窗口>首选项> PyDev >口译员> Python Interpreter
2)删除之前添加的Python Interpreter路径
3)添加“New”Python Interpreter并选择python.exe路径
4)检查Libraries选项卡(我在这一步发现了问题。)
检查你的路径名,是真是假? Eclipse 检测到“C:\Python27\lib”,但它应该是“C:\Python27\libs”和“C:\Python27\Lib”。
I had a similar problem before. I solved the problem by this steps:
1)Window > Preferences > PyDev > Interpreters > Python Interpreter
2)Delete the Python Interpreter path you added previously
3)Add "New" Python Interpreter and choose python.exe path
4)Check Libraries tab (I found the problem at this step.)
Check your path name, is it true or false? Eclipse detect "C:\Python27\lib" but it should be "C:\Python27\libs" and "C:\Python27\Lib".
pycassa 是否在 PYTHONPATH 上的目录中作为符号链接找到? Pydev 显然有一个错误,它的代码分析无法遵循符号链接(因此不会看到您的库)。 python 解释器当然可以。
Is pycassa found as a symlink within a directory on your PYTHONPATH? Pydev apparently has a bug where its code analysis cannot follow symlinks (and hence will not see your libraries). The python interpreter can though of course.
我在 dbfpy 模块上遇到了类似的问题。
我已经下载了 tar 存档并将源文件安装在 /usr/lib/python2.7/dist-packages
有了这个,我就能够在 IDLE 中导入包,甚至在 Eclipse 中运行代码。然而,pydev 导入仍然显示为错误,并显示消息“未解决的导入”
根据 Fabio 的建议,我检查了 PyDev 文档中的强制内置函数。只需将包的名称(在我的例子中为“dbfpy”添加到 Eclipse 中 Python 解释器的“强制内置”选项卡中)即可解决问题。
I was having a similar problem with the dbfpy module.
I had downloaded the tar archive and installed the source files in /usr/lib/python2.7/dist-packages
With this I was able to import the packages in IDLE and even run the code in Eclipse. However the pydev import was still showing as an error with the message "unresolved import"
As suggested by Fabio, I checked the PyDev documentation for forced-builtins. Just adding the name of the package ("dbfpy" in my case to the Forced Builtit tab of Python Interpretr in Eclipse) solved the issue.
(我知道答案有点晚了)
如果您使用以下命令安装了 python 包: pip install django
我这样做解决了未解决的导入问题:
在日食中:
窗口>偏好设置
在左侧面板树结构中,转到:
PyDev >解释器 - Python
在右上方面板中,确保选择了正确的解释
在右下面板中,单击新建文件夹,导航到 python 安装站点包(通常在 c:\Python33\Lib\site-packages 中)并搜索以 .egg-info 结尾的文件夹
在我的电脑中,它是“C:\Apps\Environments\Python33\Lib\site-packages\Django-1.5.4-py3.3.egg-info”,因为我在 C:\Apps\Environments 中安装了 python,应该是不同的在你的情况下。
这适用于 django 和 selenium,也应该适用于所有其他(据我所知)
(I know the answer is a bit late)
if you installed a python package using, for example: pip install django
i solved the unresolved import issue doing this:
In eclipse:
Window > Preferences
In the left panel tree structure go to:
PyDev > Interpreter - Python
In the upper right panel be sure to have the correct interpreted selected
and in the bottom right panel, click New Folder, navigate to your python installation site-packages (usually in c:\Python33\Lib\site-packages) and search for a folder that ends with .egg-info
In my pc it is "C:\Apps\Environments\Python33\Lib\site-packages\Django-1.5.4-py3.3.egg-info" since i installed python in C:\Apps\Environments, should be different in your case.
This worked with django and selenium, should work with all others as well (as far as i know)
将对应的以 '.egg-info' 结尾的包文件夹添加到 PyDev >解释器 - Python - 库将解决这个问题。
在Linux中,通常位于/usr/local/lib/pythonX.X/dist-packages下
Adding the corresponding package folder ending with '.egg-info' to PyDev > Interpreter - Python - library will resolve the problem.
In Linux, it is usually under /usr/local/lib/pythonX.X/dist-packages
在环境变量中添加站点包路径。
右键单击
。
完成后,删除python解释器并在eclipse中再次添加它。
右键单击项目名称
。
希望它有效。
Add site-packages path in environmental variables.
Right click on
.
After that is done, remove the python interpreter and add it again in eclipse.
right click project name in
.
Hope it works.