I'm writing a Python application that is executable. It reads and writes to a file. The application uses wx for a GUI and has been given the following permissions:

chmod +x app.py

When I load the application from the terminal like so:


The application loads and causes no errors.

However, when I double click the app.py file and click 'execute', everything works perfectly except for the reading and writing of this file. This is a major part of the program and causes errors.

I cannot, for the life of me, understand why this is not working.

I have attempted to set it so that it loads as the root user each time with no luck. I have also been developing as the root user the entire time, so I shouldn't see any issues.

I am using the default Raspbian OS.

  • 1
    What is the name of the file you are reading/writing? In your program are you using the full path of the file? – Craig Apr 16 '13 at 19:49
  • So that we can have more documentation, please post your code on Pastebin. Try creating the app without the GUI - this way you can see if wx is causing problems or the base python script. NOTE: I don't believe that WX on the Pi is entirely stable. Are you sure that you cannot use Tkinter instead? – xxmbabanexx Apr 17 '13 at 0:21
  • I'll try changing the path and see if that solves the issue. I was using WX as it was the only option I found when searching for a GUI tool, I'll try adapt Tkinter to work with it instead. – phalt Apr 17 '13 at 5:56

Is the file in the same directory as app.py? There are a couple of gotchas about running from a file manager.

Consider the following trivial program, living on my desktop:

import os
import time

print "Working directory: ", os.getcwd()

If I run it in the terminal like ./pytest.py (after doing cd Desktop), I get:

Working directory:  /home/pi/Desktop

If I run it from File Manager, however, I get:

Working directory:  /home/pi

and that's even with the File Manager window opened to the Desktop folder. (The 10 second delay is just there to stop a terminal window closing before I can read it.)

You have to be very careful with paths; you can't assume that File Manager will have anything useful set for the current working directory. See if you have more luck setting os.setcwd() to the right directory.

Finally, doing stuff as the root user won't help you here. The root user gives you powers it assumes you know how to use. If you're not even conversant with working directories, you might not want to have that power, as you'll be surprised when you accidentally delete something important. Everybody does something stupid as root once; there's no excuse if you do it more than once ...

  • I'll try doing the os.setcwd() and see if that helps. Thanks! – phalt Apr 18 '13 at 10:32

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.