Dismiss Notice
Join Physics Forums Today!
The friendliest, high quality science and math community on the planet! Everyone who loves science is here!

Raspbian Permission Denied

  1. Jul 14, 2013 #1

    TheDemx27

    User Avatar
    Gold Member

    I'm thinking this problem should be easy to fix.

    I recently got a raspberry pi and did a few test python programs on it to make sure everything was working. Whenever I try to execute the python script I get this message:

    Code (Text):

    pi@raspberrypi ~ $ ./test.py
    -bash: ./test.py: Permission denied
     
    I've tried changing permissions to the user pi, but it has no effect.
    BTW: I'm accessing the pi from my desktop via SSH if that has anything to do with it.

    Thanks.
     
  2. jcsd
  3. Jul 14, 2013 #2

    Borek

    User Avatar

    Staff: Mentor

    Try

    Code (Text):
    python test.py
    If you want to run it directly you need to add a first line telling the shell what interpreter to use:

    Code (Text):
    #!/usr/bin/python

    print "Hello world!"
     
    Last edited: Jul 14, 2013
  4. Aug 4, 2013 #3
    Look up Linux file permissions. To be very brief, you have to set the file to be executable before you can execute from the command line like you described. E.g. change the permission to allow the script to be executable:
    Code (Text):
    chmod +x test.py
    then you can run it like you were trying to:
    Code (Text):
    ./test.py
    Also, like the previous post stated, you have to have:
    Code (Text):
    #!/usr/bin/python
    on the first line of the file to inform the shell what program is needed to execute it. This works for many languages (including Perl, PHP, Octave, etc).

    Alternatively, you can just call the Python interpreter directly on files without that line, and without setting file permissions with:
    Code (Text):
    python test.py
    as long as "python" is an executable file in your PATH (something else you may want to look up).
     
  5. Aug 4, 2013 #4

    jim mcnamara

    User Avatar

    Staff: Mentor

    Code (Text):

    which python  # shows if python is in your PATH (environment variable)\
    ls -l test.py   # shows if permissions allow execute
     
    permissions look like this
    -rwxrwxrwx

    black - owner perms, blue - group perms red - "other" (world) perms

    r = read permission
    w = write permission
    x = execute permission

    So, I execute
    Code (Text):
    ls -l test.py
    and get

    Code (Text):
    -rw-r--r--
    It means the owner - you - cannot execute the file.

    Code (Text):
    chmod 750 test.py
    gives perms:
    Code (Text):
    rwxrw----
    Can you see if you now have execute permission?
     
  6. Aug 5, 2013 #5

    epenguin

    User Avatar
    Homework Helper
    Gold Member

    :confused: raspberry pi?
     
  7. Oct 7, 2013 #6

    Borek

    User Avatar

    Staff: Mentor

Know someone interested in this topic? Share this thread via Reddit, Google+, Twitter, or Facebook




Similar Discussions: Raspbian Permission Denied
  1. Permission denied ? c++ (Replies: 16)

Loading...