-1

I have made 2 games, one is pong (using Pygame), and the other one is a text-based quiz. These codes I have made using Python 2.7.1 on Windows laptop. My question is how can I run it on the Pi (which is running Raspbian Wheezy) as an application or from a software which runs Python files. Thank you.

5

The simplest way to run the program is by typing python mygame.py

If you want to be able to run the program by double clicking on it, or by just typing the filename, it's a little different than in Windows. The file needs to be executable, and have a shebang.

To make a file executable you'll need to do 2 things:

  1. Add a shebang to the top of your program's main file. This tells your OS how to interpret a seemingly random collection of text. In python, the appropriate shebang is #!/usr/bin/env python

  2. Tell the OS that it's okay to run the file as an executable chmod +x mygame.py

If you have a colored terminal, typing ls -l should now show the filename in green.

It's also worth noting that linux permissions are a little different than in Windows. Using the same ls -l command above, you should see a file owner and group. You'll want to make sure that the owner and group match your user. If it doesn't you can change it with the command sudo chown pi:pi mygame.py (assuming your user is named pi).

Your Answer

By clicking “Post Your Answer”, you agree to our terms of service, privacy policy and cookie policy

Not the answer you're looking for? Browse other questions tagged or ask your own question.