1

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.

Community
  • 1
  • 1
gentimouton
  • 145
  • 3
  • 11

1 Answers1

0

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:

import sys
print '\n'.join(sorted(sys.path))
import pygame.locals
print pygame
print pygame.locals

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

Fabio Zadrozny
  • 24,814
  • 4
  • 66
  • 78
  • Thanks for your help :-) I've made a new pydev project with your program in it. I removed pygame from the forced built-ins. Your program outputs:`/home/tho/.eclipse/org.eclipse.platform_3.7.0_155965261/plugins/org.python.pydev.debug_2.3.0.2011121518/pysrc /home/tho/workspace/test/src /home/tho/workspace/test/src /usr/local/lib/python3.2 /usr/local/lib/python3.2/lib-dynload /usr/local/lib/python3.2/plat-linux3 /usr/local/lib/python3.2/site-packages /usr/local/lib/python32.zip` ....... – gentimouton Dec 30 '11 at 06:33
  • ... Then the error for the line `import pygame.locals`: `File "/usr/local/lib/python3.2/site-packages/pygame/__init__.py", line 99, in from pygame.base import * ImportError: libSDL-1.2.so.0: cannot open shared object file: No such file or directory` – gentimouton Dec 30 '11 at 06:34
  • Errors in error log: as far as PyDev is concerned, see those links to screenshots: [first part](http://img4.imageshack.us/img4/5547/screenshotat20111229222.png) and [the rest](http://img847.imageshack.us/img847/5547/screenshotat20111229222.png) – gentimouton Dec 30 '11 at 06:36
  • It seems that the error is in your compilation of pygame... (because the import is failing) is there any reason you didn't get the one from ubuntu directly? (i.e.: remove your compilation and do something as sudo apt-get install python-pygame. Note: I'm not on Linux right now, so, the package name may be a bit different, especially if it's for python 3). – Fabio Zadrozny Dec 30 '11 at 09:38
  • Ah I'm sorry to have wasted your time if that problem does not deal with pydev but rather with compiling pygame :/ The apt-get only has pygame for python2.6 (the default python on Ubuntu11.11). I followed the instructions from [pygame.org](http://www.pygame.org/wiki/CompileUbuntu?parent=Compilation). I'll reinstall pygame, double check for compilation errors (although nothing struck me when I installed it), and get back to you. – gentimouton Dec 30 '11 at 23:40
  • I 'apt-get auto-remove', then recompiled and reinstalled pygame for python3.2, and now 'except pygame.error' does not indicate any red lines in the editor anymore. 'import pygame' 'from pygame.locals import *' and ctrl-click on locals still does not work on ubuntu, but I can live without it. pygame has a package called constants, which I think is stored in 'constants.cpython-32m.so'. On both Windows and Ubuntu, autocompletion still does not suggest 'constants' when I write 'import pygame.con', but once again, I should be able to live with it. – gentimouton Jan 01 '12 at 21:33
  • Humm, PyDev can't really find about constants.cpython-32m.so because of its strange format (I guess something changed on Python 3, because by looking at it, it doesn't seem like Python would find it either, or maybe that's a special construct done by the pygame guys -- I have to take a better look at it). Please report that as a bug in the PyDev sf tracker. – Fabio Zadrozny Jan 02 '12 at 09:37