1

I'm trying to run a pygame script on a vps server, and I'm receiving an error on the pygame.display.init().

Following the directions found here http://www.pygame.org/docs/ref/display.html#pygame.display.init and in other sources, I used all this configurations before the init():

os.environ["​​SDL_VIDEODRIVER"]="dummy"

os.environ["SDL_VIDEODRIVER"]="x11"

os.environ["SDL_VIDEODRIVER"]="dga"

os.environ["SDL_VIDEODRIVER"]="fbcon"

os.environ["SDL_VIDEODRIVER"]="directfb"

os.environ["SDL_VIDEODRIVER"]="ggi"

os.environ["SDL_VIDEODRIVER"]="vgl"

os.environ["SDL_VIDEODRIVER"]="svgalib"

os.environ["SDL_VIDEODRIVER"]="aalib"

So, the "dummy" option causes the script to go into a loop. Any other option give me the error:

<class 'pygame.error'>: No available video device

I have x11 installed. I'm calling the python script from a php file, so, I would expect the graphic output to go inside the browser, or, the "video device" to be set automatically as the user browser. Not happening.

Russia Must Remove Putin
  • 374,368
  • 89
  • 403
  • 331
Leandro Guedes
  • 111
  • 1
  • 2
  • 14
  • 1
    x11 is a desktop windowing system, and doesn't interact with a web browser in normal situations. May want to take a gander at http://stackoverflow.com/questions/8452927/is-it-possible-to-run-pygame-or-pyglet-in-a-browser – Steven V Jun 29 '14 at 20:32
  • Thanks @Steven V. Actually I don't need it to be in a browser, I just have a graphic output that I want to display. I would expect some behavior as on line games, although my script is not a game. I'm reading the pyjs carefully... – Leandro Guedes Jun 29 '14 at 20:57
  • @LeandroGuedes so you are expecting the output of the pygame screen to appear in a browser? – Bartlomiej Lewandowski Jun 29 '14 at 21:50
  • @Bartlomiej Lewandowsk, that's right. Am I missing something? Once I'll call the script from a browser, I would expect the output to appear in the same window, or that it would open another window. But if there is any other way for me to show the output that is not through the browser, it's not a problem. – Leandro Guedes Jun 29 '14 at 22:53

1 Answers1

1

Are you ssh'd into the vps server? Have you tried x forwarding, ssh -X user@server.com then when you run the script from the command line it should open on your window

Jacob Minshall
  • 1,044
  • 9
  • 15
  • It opens the terminal, that works fine, but I can't run the python script with the pygame (the screen just blinks). What I need is to call the script using http, like http://myserver/run_python.php, and the php fil calls the script. It's working, but I have the `pygame.display.init()` issue. – Leandro Guedes Jun 29 '14 at 21:50
  • PHP will not send PyGame screen to your local computer using browser. – furas Jun 29 '14 at 22:22
  • But could I tell PyGame to open the screen in the server itself and this output be sent to the visitor of the site? – Leandro Guedes Jun 29 '14 at 22:56
  • Probably you will need some tool to grab server screen as video stream and some video stream server to send it to client browser. – furas Jun 29 '14 at 23:38
  • PyGame was not created to work with web browser and probably no one tries to use it in this way. Or some try to do it but no one has succeeded. – furas Jun 29 '14 at 23:44
  • I believe you're right @furas. But how the online games written on PyGame work? I believe there are online games written on it. – Leandro Guedes Jun 30 '14 at 02:59
  • @LeandroGuedes it would be great if you provided a link. – Bartlomiej Lewandowski Jun 30 '14 at 08:24
  • 1
    Games running in browser are made with `Flash` or `HTML+CSS+JS` (see: [Stencyl](http://www.stencyl.com/), [Flixel](http://flixel.org/), [Impact](http://impactjs.com/)) . With PyGame you can create `client-server` game. You have to programs: `client` - uses PyGame, runs on (local) user computer, `server` - doesn't use PyGame (eventually it prints some text in console, or it only sends text to log files), works on server. Client sends to server player position, etc. Server sends to client enemies (other players) positions, etc. That's all. – furas Jun 30 '14 at 12:40
  • @BartlomiejLewandowski, I'm sorry, that's the link: [http://scripts.astronomia.blog.br](http://scripts.astronomia.blog.br). The "submit" button calls it. – Leandro Guedes Jun 30 '14 at 12:51
  • 1
    @LeandroGuedes I was asking about any online game links that use pygame. In my opinion, it is very difficult and pointless to forward a server output to a browser. – Bartlomiej Lewandowski Jun 30 '14 at 13:33
  • Thank you, @BartlomiejLewandowski. I found this link [http://www.dreamincode.net/forums/topic/300693-how-to-play-pygame-using-webpages/](http://www.dreamincode.net/forums/topic/300693-how-to-play-pygame-using-webpages/) that goes with what you and furas said. I'll try to change my approach: save an image and send it to the client. All the buttuns that I have I'll try to rebuild in php to work on the browser, in such a way that PyGame only generates and save images. Thank you so much! – Leandro Guedes Jun 30 '14 at 14:45