eirasys
Posts: 5
Joined: Wed Sep 13, 2017 3:50 pm

pygame library error?

Wed Sep 13, 2017 4:01 pm

Can't find any error in this code!
Run the process from LXTerminal 'python3 example.py' then close the application window.
Do it several times. The third time you close the app it will hang up and you need to close the LXTerminal window.
Looks like a bug in pygame lib, maybe some memory leak? Any better way to quit pygame instead of pygame.quit()
How to avoid this problem?

Code: Select all

import pygame 

# Initialize window
pygame.init()
windowSurface=pygame.display.set_mode((512,512),0,32)

print(pygame.version.ver)

while True:
    event = pygame.event.wait()

    if event.type==pygame.QUIT:
       break

print ("END")
pygame.quit()

User avatar
paddyg
Posts: 1996
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: pygame library error?

Wed Sep 13, 2017 10:35 pm

Hi, I've just run this lots of times on ubuntu laptop and on RPi3 with raspbian stretch, python3 and python2 and it seemed fine. I ran top in another terminal and there was no sign of memory usage increasing. The only thing I've done since burning the SD is increase the GPU memory, set up vnc server and a couple of python modules.
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

eirasys
Posts: 5
Joined: Wed Sep 13, 2017 3:50 pm

Re: pygame library error?

Thu Sep 14, 2017 10:29 am

I'm using gpu_mem=800 in /boot/config.txt, this should not be the problem.
Tried as superuser, both with Root Terminal and with 'sudo python3 example.py'
but the problem remains.
Can't understand why only in the 3rd run this thing happens.
Tried inside Remote Desktop and the window is blocked only at the 4th execution.
Looks like Terminal configuration problems.
This bothers greatly in code development and testing...
Any hint?

Code: Select all

root@raspberrypi:/home/pi/Desktop/PROJECTO 2DDRAW# python3 example.py
1.9.2a0
END
root@raspberrypi:/home/pi/Desktop/PROJECTO 2DDRAW# python3 example.py
1.9.2a0
END
root@raspberrypi:/home/pi/Desktop/PROJECTO 2DDRAW# python3 example.py
1.9.2a0
END
>>>> pygame window does not close but END message appears in the LXTerminal window,
>>>> LXTerminal is also hanged up, but closing it works to terminate the process.

User avatar
paddyg
Posts: 1996
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: pygame library error?

Thu Sep 14, 2017 10:46 am

Hi, the default pygame on the raspbian stretch image seems to be 1.9.3 (see attached) can you upgrade to that?
Screenshot01.jpg
Screenshot01.jpg (52.26 KiB) Viewed 450 times
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

eirasys
Posts: 5
Joined: Wed Sep 13, 2017 3:50 pm

Re: pygame library error?

Thu Sep 14, 2017 11:41 am

I'm working with the Raspberry Pi 2 Model B Rev 1.1
Executed the following pygame upgrade and it says it is in the most recent version.
How did you install the new version 1.9.3?

Code: Select all

sudo apt-get install python-pygame
sudo apt-get install python3-pygame

User avatar
paddyg
Posts: 1996
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: pygame library error?

Thu Sep 14, 2017 1:51 pm

pygame was already installed in the raspbian stretch image. Are you using jessie? (you can tell by running cat /etc/os-release) If you are then you could try upgrading using pip. Something like

Code: Select all

$ sudo python3 -mpip install pygame --upgrade
you might be able to apt-get install from an alternative source along the lines of this PS this might not cure your issue but at least it eliminates one possibility!
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

eirasys
Posts: 5
Joined: Wed Sep 13, 2017 3:50 pm

Re: pygame library error?

Thu Sep 14, 2017 2:51 pm

Jessie, yes I have, but I didn't had any idea about its existence... I know now that its the latest Raspbian OS interface.
Looks the righ way, but now I have another error with no SDL installed. There is an old version SDL1.2 and a new one SDL2.
How to install?

Code: Select all

Collecting pygame
  Downloading pygame-1.9.3.tar.gz (3.0MB)
    100% |████████████████████████████████| 3.0MB 36kB/s 
    Complete output from command python setup.py egg_info:
    
    
    WARNING, No "Setup" File Exists, Running "config.py"
    Using UNIX configuration...
    
    /bin/sh: 1: sdl-config: not found
    /bin/sh: 1: sdl-config: not found
    /bin/sh: 1: sdl-config: not found
    
    Hunting dependencies...
    WARNING: "sdl-config" failed!
    Unable to run "sdl-config". Please make sure a development version of SDL is installed.
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-gjfivnwq/pygame/

By the way I added your cat command to 'ver' alias in the file '/home/pi/.bashrc'
may be usefull for others looking for hardware and OS information:

Code: Select all

#Raspberry Pi Hardware and OS Version
alias ver='cat /proc/device-tree/model; echo; echo; cat /proc/cpuinfo; echo; uname -a; echo; cat /etc/os-release'

User avatar
paddyg
Posts: 1996
Joined: Sat Jan 28, 2012 11:57 am
Location: UK

Re: pygame library error?

Thu Sep 14, 2017 5:23 pm

Hi, it might be
$ sudo apt-get install libsdl2-dev
(this runs on my RPi but pygame already works (but using x11))
there's something about it here https://wiki.libsdl.org/Installation where they point you to the ready built sdl2 here https://buildbot.libsdl.org/sdl-builds/ ... i/?C=M;O=D though I'm not sure what you need to do with that.

PS or see here https://raspberrypi.stackexchange.com/q ... sdl-config where they suggest installing libsdl1.2-dev
also https://groups.google.com/forum/?hl=en-GB&fromgroups=#!forum/pi3d

eirasys
Posts: 5
Joined: Wed Sep 13, 2017 3:50 pm

Re: pygame library error?

Thu Sep 14, 2017 8:50 pm

Why should this look so complex?!
followed this link https://askubuntu.com/questions/344512/ ... -in-ubuntu
install only libraries: sudo apt-get install libsdl2-2.0
install development: sudo apt-get install libsdl2-dev
After a lot of waiting to download, compile and install SDL2, well it does not work!

Followed SDL1.2 installation, quite easy:
sudo apt install libsdl1.2-dev
By the way it also works for SDL2...
sudo apt install libsdl2-dev

New error when running:
sudo python3 -m pip install pygame --upgrade

Code: Select all

Collecting pygame
  Using cached pygame-1.9.3.tar.gz
    Complete output from command python setup.py egg_info:
    
    
    WARNING, No "Setup" File Exists, Running "config.py"
    Using UNIX configuration...
    
    
    Hunting dependencies...
    SDL     : found 1.2.15
    FONT    : not found
    IMAGE   : not found
    MIXER   : not found
    PNG     : found
    JPEG    : found
    SCRAP   : found
    PORTMIDI: not found
    PORTTIME: not found
    FREETYPE: found 2.6.0
    Missing dependencies
    
    ----------------------------------------
Command "python setup.py egg_info" failed with error code 1 in /tmp/pip-build-vc3l4uju/pygame/

Found this to install pygame:
viewtopic.php?f=32&t=33157

Code: Select all

$ sudo apt-get install mercurial 
$ hg clone https://bitbucket.org/pygame/pygame
$ cd pygame

$ sudo apt-get update&&sudo apt-get install libsdl-dev libsdl-image1.2-dev libsdl-mixer1.2-dev libsdl-ttf2.0-dev 
$ sudo apt-get install libsmpeg-dev libportmidi-dev libavformat-dev libswscale-dev
$ sudo apt-get install python3-dev python3-numpy

$ python3 setup.py build 
$ sudo python3 setup.py install

Now I have pygame version 1.9.4.dev0,
but the initial problem remains the same, the window blocks at the third attempt...

Your upgrade command works now without errors, we can use it to choose a stable version,
it will uninstall 1.9.4.dev0 version:

Code: Select all

sudo python3 -m pip install pygame==1.9.3 -- upgrade
Hope it can be usefull for more people running similar problems :?,
not the original problem 1.9.3 gives the same result

Return to “Python”

Who is online

Users browsing this forum: No registered users and 20 guests