0

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.

asked Jan 13, 2016 at 22:07

1 Answer 1

6

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).

Ghanima
16k17 gold badges66 silver badges127 bronze badges
answered Jan 13, 2016 at 22:13
0

Your Answer

Draft saved
Draft discarded

Sign up or log in

Sign up using Google
Sign up using Email and Password

Post as a guest

Required, but never shown

Post as a guest

Required, but never shown

By clicking "Post Your Answer", you agree to our terms of service and acknowledge you have read our privacy policy.

Start asking to get answers

Find the answer to your question by asking.

Ask question

Explore related questions

See similar questions with these tags.