Pydev 说“未解决的导入”错误

发布于 2024-12-02 15:40:14 字数 376 浏览 1 评论 0原文

嗯.. 有时,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 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(11

不忘初心 2024-12-09 15:40:14

有同样的问题。最后,我通过在“首选项”>“删除旧解释器”中解决了该问题。 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.

在梵高的星空下 2024-12-09 15:40:14

可能您的 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).

眼眸 2024-12-09 15:40:14

如果找不到所需的模块,则会出现未解析的导入。在当前工作目录和 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/

離殇 2024-12-09 15:40:14

我通过重新创建解释器解决了。 pedev.org 上有一个指南:

如果我在配置后在系统 PYTHONPATH 中添加新内容会怎样?
是吗?

如果您向 python 安装添加某些内容,则需要
将其手动添加为系统 PYTHONPATH 中的“新文件夹”(如果是
仍然不在 PYTHONPATH 中的文件夹下)或(推荐)删除
您的口译员并再次添加,然后按“应用”。

请注意,如果您添加的库已位于
PYTHONPATH,您至少必须进入解释器首选项并
按“应用”,以便清除其内部缓存(在
配置完成,PyDev 的一切都已确定)

感谢 Fabio Zadroznynicodjimenez

I solved by recreate the interpreter. There is a guide at pedev.org:

What if I add something new in my System PYTHONPATH after configuring
it?

If you add something to your python installation, you need to either
add it manually as a 'new folder' in the System PYTHONPATH (if it's
still not under a folder in the PYTHONPATH) or (recommended) remove
your interpreter and add it again, then, press apply.

Note that if you added a library that's already under a folder in the
PYTHONPATH, you have to at least go to the interpreter preferences and
press apply so that it clears its internal caches (after the
configuration is done, things are set in stone for PyDev)

Thanks for Fabio Zadrozny and nicodjimenez.

沦落红尘 2024-12-09 15:40:14

在 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

失退 2024-12-09 15:40:14

我以前也遇到过类似的问题。我通过以下步骤解决了问题:

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".

Check and add true path

File path

相思故 2024-12-09 15:40:14

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.

只有一腔孤勇 2024-12-09 15:40:14

我在 dbfpy 模块上遇到了类似的问题。

  1. 我已经下载了 tar 存档并将源文件安装在 /usr/lib/python2.7/dist-packages

  2. 有了这个,我就能够在 IDLE 中导入包,甚至在 Eclipse 中运行代码。然而,pydev 导入仍然显示为错误,并显示消息“未解决的导入”

  3. 根据 Fabio 的建议,我检查了 PyDev 文档中的强制内置函数。只需将包的名称(在我的例子中为“dbfpy”添加到 Eclipse 中 Python 解释器的“强制内置”选项卡中)即可解决问题。

I was having a similar problem with the dbfpy module.

  1. I had downloaded the tar archive and installed the source files in /usr/lib/python2.7/dist-packages

  2. 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"

  3. 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.

一个人的夜不怕黑 2024-12-09 15:40:14

(我知道答案有点晚了)
如果您使用以下命令安装了 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)

感情废物 2024-12-09 15:40:14

将对应的以 '.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

海螺姑娘 2024-12-09 15:40:14

在环境变量中添加站点包路径。

右键单击

计算机->属性->高级系统设置->环境的
变量

完成后,删除python解释器并在eclipse中再次添加它。
右键单击项目名称

日食 -->属性--> python解释器

希望它有效。

Add site-packages path in environmental variables.

Right click on

computer -> properties -> advanced system settings -> Environmental
variables

.

After that is done, remove the python interpreter and add it again in eclipse.
right click project name in

eclipse --> properties --> python interpreter

.

Hope it works.

~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文