1

I am using Linux Mint 17 (Ubuntu 14.04) and already got pygame 1.9.2 working in Eclipse on my Windows PC. Now I also installed it on this machine, but it doesn't work. Thus there is no apt-get for python3-pygame I downloaded the source from https://bitbucket.org/pygame/pygame and built and installed it without getting errors.

When running the following on the command line I receive no error:

import pygame
pygame.init()

If I try the same in an Eclipse PyDev project I get the error: "Undefined variable from import: init".

First I thought that my Interpreter was not set up correctly, but the path where pygame is installed is added to the libraries (/usr/local/lib/python3.4/dist-packages). I realized that for Python2.7 pygame is installed in /usr/lib/pytho2.7/dist-packages instead, but this directory doesn't exist for python3.4 on my machine.

Since it seems to work on the command-line it must have something to do with the Eclipse or Pydev settings, right?

UPDATE: Ok, now things are getting really confusing. I found out that pygame indeed is also working from within eclipse if I run the project, but only giving me these error messages for eg. pygame.init(), pygame.QUIT, pygame.K_ESCAPE, pygame.KEYDOWN. I find it very strange, because pygame.time.Clock() or pygame.display.set_caption() don't give error messages. So I only get undefined variable from import errors (also see here How do I fix PyDev "Undefined variable from import" errors? ).

Community
  • 1
  • 1
freeDom-
  • 362
  • 4
  • 20

3 Answers3

2

Use sudo pip3 install pygame, pip3 should work assuming you have python3 and setuptools installed.
You can install pip3 using sudo apt-get install python3-pip and then use sudo pip3 install package_name to get whatever you want.

Meghdeep Ray
  • 5,262
  • 4
  • 34
  • 58
  • Seems like a good idea in the first place.. Would have made it way easier for me to install it.. Nevertheless it returns: "Requirement already satisfied (use --upgrade to upgrade): pygame in /usr/local/lib/python3.4/dist-packages Cleaning up..." – freeDom- Jul 22 '15 at 16:08
  • You could use `sudo pip3 uninstall pygame` to remove the existing install and then reinstall it. Should stabilize everything. – Meghdeep Ray Jul 22 '15 at 16:15
  • Mhh, it seems that pip3 also doesn't have the pygame package: "Could not find any downloads that satisfy the requirement pygame".. I was building it myself only, because pip also doesn't support a python3 pygame build. – freeDom- Jul 22 '15 at 22:09
  • I uninstalled it now and reinstalled it using sudo pip3 install hg+https://bitbucket.org/pygame/pygame. Unfortunately this doesn't work aswell.. I also think that it is an issue with Eclipse, since it is working well using the python command line... – freeDom- Jul 22 '15 at 22:33
  • I am one step further.. It is probably a PyDev error.. There are a lot of threads around, but still didn't find a solution... – freeDom- Jul 23 '15 at 01:17
1

The only thing which worked for me (I spent two days now finding out what the problem is) is to add "pygame" to the forced builtins for the Interpreter (Window -> Preferences -> PyDev -> Interpreter -> Python Interpreter -> Forced Builtins Tab -> New -> pygame.

This is only a workaround, but at least I am rid of those errors for now and auto-completion still works. I didn't find any other solution that worked for me so far.

freeDom-
  • 362
  • 4
  • 20
0

For me the problem was resolved by importing *. instead of:

import pygame

try this:

from  pygame import *

now instead of calling init() by saying pygame.init() just use init() also you should not have to explicitly call using pygame. for the most part.

NOTE: after playing around with this in Eclipse I did end up having to use both:

import pygame
from pygame import *

for whatever reason one of my functions only works if I have pygame.even.get() but the test of my code does not need to use pygame. (I am sure there is a perfectly good reason but I am still very new to python)

Mike - SMT
  • 14,784
  • 4
  • 35
  • 79