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