Pydev“从导入中取消定义变量”在 Ubunutu 上使用 pygame 但不能在 Windows 上使用
简而言之,
在 Ubuntu 11.10 上,对于 pygame 库,pydev 报告“导入时未定义变量”。在 Windows 7 上,一切都很好。在这两个平台上,代码都可以正常运行。
此错误与此线程相同(以及一堆 其他)。删除并重新添加我的解释器并没有改变任何东西。我还尝试将 pygame 作为强制内置库包含在内,但它没有改变任何内容(我检查了 pygame 是否在系统 PYTHONPATH 中)。
配置
在 Ubuntu 和 Windows 上,我使用 Eclipse Indigo 和 Python 3.2。
在 Ubuntu 上,我使用的是:
- Ubuntu 11.10
- Pygame 1.9.2pre 从 pygame Hg 存储库编译。构建并安装后,site-packages/pygame 文件夹包含一堆 .so 和 .py 文件。
在 Windows7 上:
- 带 SP1 的 Windows 7 专业版
- Pygame 1.9.2pre 来自 lfd.uci.edu。 MSI 在 site-packages/pygame 文件夹中创建了一堆 .pyd 和 .py。
我知道静态分析不能进入 Ubuntu 上的 .so 文件。我也明白Python是一种动态语言。因此 pydev 具有静态分析固有的局限性。但是 Windows 7 上的 pydev 设法链接 .pyd 文件内的类,这些类是动态库。为什么?我怎样才能让它在 Ubuntu 上运行?
提示?
import pygame
from pygame.locals import *
使用Ubuntu中的上述代码,我可以按住ctrl键单击(或f3)到pygame包,但不能到pygame.locals。在 Windows 上我可以同时访问两者。
import pygame
import pygame.locals
from pygame.locals import *
现在我可以转到 pygame.locals。我想这有助于 pydev 弄清楚“期望”什么,因为 locals.py 实际上存在于 site-packages/pygame 文件夹中。但我不想仅仅为了适应 pydev 而改变我的所有代码。
无论如何,下面的行在 Ubuntu 上仍然会引发“导入时未定义的变量”,但在 Windows 上不会。
except pygame.error:
PS:如果有帮助的话,我有一台 64 位 Lenovo T410,并安装了 64 位的所有内容。
In a nutshell
On Ubuntu 11.10, for the pygame library, pydev reports "undefined variables from imports". On Windows 7, everything is fine. On both platforms, the code works properly.
This is the same error as this thread (and a bunch of others). Removing and re-adding my interpreter did not change anything. I also tried to include pygame as a forced built-in lib, but it did not change anything (I checked that pygame was in system PYTHONPATH).
Configs
On both Ubuntu and Windows, I'm using Eclipse Indigo and Python 3.2.
On Ubuntu, I'm using:
- Ubuntu 11.10
- Pygame 1.9.2pre compiled from the pygame Hg repo. When built and installed, the site-packages/pygame folder contains a bunch of .so and .py files.
On Windows7:
- Windows 7 pro with SP1
- Pygame 1.9.2pre from lfd.uci.edu. The MSI created a bunch of .pyd and .py to the site-packages/pygame folder.
I understand that static analysis can't go inside .so files on Ubuntu. I also understand that Python is a dynamic language. Hence pydev has limitations inherent to static analysis. But pydev on Windows 7 manages to link the classes inside .pyd files, which are dynamic libs. Why? And how could I make it work on Ubuntu?
Hints?
import pygame
from pygame.locals import *
With the above code in Ubuntu, I can ctrl-click (or f3) to the pygame package, but not to the pygame.locals. On Windows I can go to both.
import pygame
import pygame.locals
from pygame.locals import *
Now I can go to pygame.locals. I guess that helped pydev to figure out what to "expect", since locals.py actually exists in the site-packages/pygame folder. But I don't want to change all my code just to suit pydev.
Anyway, the line below still raises "undefined variable from import" on Ubuntu, but not on Windows.
except pygame.error:
PS: In case that helps, I have a 64 bit Lenovo T410, and installed everything for 64 bits.
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(1)
我刚刚在 Ubuntu 上测试了它,它似乎对我来说工作正常...您可以发布以下内容来尝试帮助您修复它:
1。如果您添加了“pygame”,请从强制内置中删除它(这个特定用例不需要它......通过查看其结构,静态分析器似乎应该能够正确处理它,并且pygame 中的 .so 文件将自动由 shell 处理,因此无需显式处理它)。
2.拥有一个程序:
当您从 PyDev 启动它时,它会提供什么输出? (我有兴趣了解 pygame 的完整路径,它是否会在运行时抛出 ImportError 以及完整的 PYTHONPATH)
3。您的错误日志中有错误吗? (PyDev 能够内省 .so 文件,但它会启动一个单独的 python shell 并通过套接字与其通信,因此,可能有什么东西阻塞了那里的东西)。
I've just tested it here on Ubuntu and it seems to work properly for me... can you post the following to try to help you fix it there:
1. Remove the 'pygame' from your forced builtins if you added it (it shouldn't be needed for this specific use-case... by looking at its structure it seems the static analyzer should be able to deal with it properly, and the .so files in pygame will automatically be handled by a shell, so, it's not necessary to explicitly deal with it).
2.Having a program with:
What's the output it gives you when you launch it from PyDev? (I'm interested in knowing the full path to pygame, whether it'll throw an ImportError in runtime and your full PYTHONPATH)
3. Do you have some error in your error log? (PyDev is able to introspect .so files, but it'll launch a separate python shell and communicate with it through sockets, so, it's possible that something is blocking things there).