aidanmack
Posts: 22
Joined: Thu Jun 14, 2012 11:00 am

pygame / putty / unable to open console

Tue Jun 04, 2013 12:11 pm

Hi im running some script on my pi via putty.

However the code requires a console to be opened. Im not so bothered about it opening on my work machine (windows) so long as it opens on the pi.

The line of script in question is
screen = pygame.display.set_mode([800, 600

but when ever I run that line I get...
pygame.error: Unable to open a console terminal

Can I some how have it ignore the fact that the command is via putty?

Thanks
Aidan

User avatar
winkleink
Forum Moderator
Forum Moderator
Posts: 279
Joined: Mon Nov 07, 2011 9:12 am
Location: UK
Contact: Website

Re: pygame / putty / unable to open console

Tue Jun 04, 2013 1:06 pm

pygame requires a graphic environment to be enabled or you need a dummy screen.

I did this for a usb controlled stepper motor thing I did a couple of months ago.
http://winkleink.blogspot.co.uk/2013/04 ... otors.html

The important bit is:

Code: Select all

import os

os.environ["SDL_VIDEODRIVER"] = "dummy"
pygame.init()
Also, note to use the pygame event.type to read a keyboard requires an active display and 'dummy' will not work.

Alternatively, you could use Xming with putty to create an Xwindow over SSH
http://simonthepiman.com/2-10-how_to_vi ... ows_PC.php

Either one will make it work.
Twitter:Winkleink
Google+: Winkleink

cae2100
Posts: 143
Joined: Tue Jan 08, 2013 10:35 am
Contact: Website

Re: pygame / putty / unable to open console

Tue Jun 04, 2013 9:57 pm

you could also use this in command line before starting the program, or somewhere on the rpi bootup:

Code: Select all

export DISPLAY=:0
and it'll just post the display up on the screen attached to the rpi itself.
If it isnt smoking and blown into pieces, it's not pushed far enough yet. :P
http://cae2100.wordpress.com

Maddo
Posts: 15
Joined: Mon May 06, 2013 4:39 am

Re: pygame / putty / unable to open console

Wed Jun 05, 2013 4:21 am

Or use screen.

aidanmack
Posts: 22
Joined: Thu Jun 14, 2012 11:00 am

Re: pygame / putty / unable to open console

Mon Jun 17, 2013 12:01 pm

Thanks for this guys,
I just got it working this morning using xming.

However how do I get the graphical ui to appear actually on the rp desktop screen?


So far I have created two profiles with xming
one that launchs the pygame window on my work pc when execute the python code via PUTTY (but doesnt appear on the pi screen)

I have also created a xming profile that allows me login like a remote desktop.
However what I see and do via this profile does not actually update on the raspberry pi desktop... if that makes sense.



Basically at some point I need the means to remotely launch a python program that will display graphics (pygame stuff) to the user who is looking at the rasp pi

Thanks
Aidan

alfem
Posts: 4
Joined: Fri Jun 29, 2012 9:57 am

Re: pygame / putty / unable to open console

Tue Jul 16, 2013 8:35 am

I am doing something like you said: running a remote script that shows pygame graphics on a netbook.

Launch your python script from a shell script like this:

#!/bin/sh
DISPLAY=0:0; sudo ./yourpythonscript.py


(Bear in mind you will need root passwd.)

Return to “Python”