Permission Denied

Discussion in 'Python' started by Tom Strickland, Aug 20, 2006.

  1. Hopefully this is a simple question. I've started to program in Python
    after an absence of about a year, so I'm very rusty. I wrote a short
    program and tried to run it using Python2.4 in Linux. I keep getting
    "permission denied" messages after entering the path to the program. I
    switched to the root directory and tried again, but got the same
    result.I ran a very similar program earlier and it ran fine.

    What am I doing wrong? The program is:


    #!/usr/bin/python2.4
    i=1
    while i<10000:
    print 'step 1',i
    i+=1
    raw_input()
    print 'step 2'


    Thank you.

    Tom
     
    Tom Strickland, Aug 20, 2006
    #1
    1. Advertising

  2. Tom Strickland

    hiaips Guest

    Tom Strickland wrote:
    > Hopefully this is a simple question. I've started to program in Python
    > after an absence of about a year, so I'm very rusty. I wrote a short
    > program and tried to run it using Python2.4 in Linux. I keep getting
    > "permission denied" messages after entering the path to the program. I
    > switched to the root directory and tried again, but got the same
    > result.I ran a very similar program earlier and it ran fine.
    >
    > What am I doing wrong? The program is:
    >
    >
    > #!/usr/bin/python2.4
    > i=1
    > while i<10000:
    > print 'step 1',i
    > i+=1
    > raw_input()
    > print 'step 2'
    >
    >
    > Thank you.
    >
    > Tom



    Is your script executable?
     
    hiaips, Aug 20, 2006
    #2
    1. Advertising

  3. Tom Strickland

    AlbaClause Guest

    hiaips wrote:

    >
    > Tom Strickland wrote:
    >> Hopefully this is a simple question. I've started to program in Python
    >> after an absence of about a year, so I'm very rusty. I wrote a short
    >> program and tried to run it using Python2.4 in Linux. I keep getting
    >> "permission denied" messages after entering the path to the program. I
    >> switched to the root directory and tried again, but got the same
    >> result.I ran a very similar program earlier and it ran fine.
    >>
    >> What am I doing wrong? The program is:
    >>
    >>
    >> #!/usr/bin/python2.4
    >> i=1
    >> while i<10000:
    >> print 'step 1',i
    >> i+=1
    >> raw_input()
    >> print 'step 2'
    >>
    >>
    >> Thank you.
    >>
    >> Tom

    >
    >
    > Is your script executable?


    That's the problem I had when I wrote my first Python script. I wrote it
    using vi, and vi doesn't save files with the executable flag set. A simple
    'chmod 755 script.py' fixed that right up.

    Then, to execute the file from from the shell prompt, I had to create a
    'bin' directory in my home folder, cuz I didn't want to litter
    my /usr/local/bin folder with useless Python scripts. (Useless because I
    wrote them to learn the language and for no other practical purpose.) Of
    course, I had to uncomment a line or two in my .bashrc file too.

    Hey, what do I know? I'm as new to this as virgins are to... Well, you get
    the idea. :p


    --
    --
    There are several things that I will never be:
    * I will never be attracted to females.
    * I will never enjoy the company of others.
    Exactly how these realities bode for my enemy, is not of my concern.
     
    AlbaClause, Aug 20, 2006
    #3
  4. In message <cPRFg.1547$>, AlbaClause wrote:

    > Then, to execute the file from from the shell prompt, I had to create a
    > 'bin' directory in my home folder, cuz I didn't want to litter
    > my /usr/local/bin folder with useless Python scripts.


    Executable files can be kept anywhere, you don't need a special directory
    for them.
     
    Lawrence D'Oliveiro, Aug 20, 2006
    #4
  5. Tom Strickland

    AlbaClause Guest

    Lawrence D'Oliveiro wrote:

    > In message <cPRFg.1547$>, AlbaClause wrote:
    >
    >> Then, to execute the file from from the shell prompt, I had to create a
    >> 'bin' directory in my home folder, cuz I didn't want to litter
    >> my /usr/local/bin folder with useless Python scripts.

    >
    > Executable files can be kept anywhere, you don't need a special directory
    > for them.


    Yes, I know, but if you want to just enter the filename at the shell prompt,
    the file has to be somewhere that it can be found. Otherwise you get the
    dreaded "command not found" error. Unless I'm doing something wrong?


    --
    --
    There are several things that I will never be:
    * I will never be attracted to females.
    * I will never enjoy the company of others.
    Exactly how these realities bode for my enemy, is not of my concern.
     
    AlbaClause, Aug 20, 2006
    #5
  6. Tom Strickland

    Stargaming Guest

    AlbaClause schrieb:
    > Lawrence D'Oliveiro wrote:
    >
    >
    >>In message <cPRFg.1547$>, AlbaClause wrote:
    >>
    >>
    >>>Then, to execute the file from from the shell prompt, I had to create a
    >>>'bin' directory in my home folder, cuz I didn't want to litter
    >>>my /usr/local/bin folder with useless Python scripts.

    >>
    >>Executable files can be kept anywhere, you don't need a special directory
    >>for them.

    >
    >
    > Yes, I know, but if you want to just enter the filename at the shell prompt,
    > the file has to be somewhere that it can be found. Otherwise you get the
    > dreaded "command not found" error. Unless I'm doing something wrong?
    >
    >

    In the most cases, PATH is preconfigured to include "." (. is the
    current directory as .. is the parent one). You can use
    ../yourpythonscript in this case.
    Another possibility is using `python script.py` to let the python
    interpreter do the work directly.
    The most "advanced" way would be expanding PATH with
    /home/youraccount/python/learning (use PATH=$PATH:/path/here..).

    Choose the one you're most comfortable with. :)

    Sincerely,
    Stargaming
    --
     
    Stargaming, Aug 20, 2006
    #6
  7. Tom Strickland

    Jorge Godoy Guest

    Stargaming <> writes:

    > In the most cases, PATH is preconfigured to include "." (. is the current
    > directory as .. is the parent one). You can use ./yourpythonscript in this
    > case.


    I most cases on Unix boxes it isn't configured to include ".". This is so for
    safety reasons (somebody might replace some command with a tampered binary or
    a script and capture information that they shouldn't have access to...).

    The solution of creating a directory and adding it to PATH is the best one,
    IMHO. Having a "~/bin" is also common for Linux and some distributions of it
    already ship with it in /etc/skel and in the PATH, so just put a link there or
    copy your scripts there.

    > The most "advanced" way would be expanding PATH with
    > /home/youraccount/python/learning (use PATH=$PATH:/path/here..).


    Yes. This is the best.

    > Choose the one you're most comfortable with. :)


    ;-) And think about security as well.

    --
    Jorge Godoy <>
     
    Jorge Godoy, Aug 20, 2006
    #7
  8. Tom Strickland

    Jorgen Grahn Guest

    On Sun, 20 Aug 2006 10:35:31 -0300, Jorge Godoy <> wrote:
    > Stargaming <> writes:
    >
    >> In the most cases, PATH is preconfigured to include "." (. is the current
    >> directory as .. is the parent one).

    >
    > I most cases on Unix boxes it isn't configured to include ".".


    Indeed -- but "Stargaming" might have missed a negation somewhere, because
    he went on to say

    [rearranged from the above]
    >> You can use ./yourpythonscript in this
    >> case.


    which is precisely what you /don't/ need to type if you have placed . in
    your $PATH.

    > The solution of creating a directory and adding it to PATH is the best one,
    > IMHO. Having a "~/bin" is also common for Linux and some distributions of it
    > already ship with it in /etc/skel and in the PATH, so just put a link there or
    > copy your scripts there.
    >
    >> The most "advanced" way would be expanding PATH with
    >> /home/youraccount/python/learning (use PATH=$PATH:/path/here..).

    >
    > Yes. This is the best.


    I wouldn't want random scripts under development ending up in my $PATH, not
    even my own.

    When you're just playing with/developing scripts, it's better to execute
    them by path (./foo.py etc). When you think they work and you have a
    long-term use for them, you install them globally, or copy, move or link
    them into your ~/bin/.

    /Jorgen

    --
    // Jorgen Grahn <grahn@ Ph'nglui mglw'nafh Cthulhu
    \X/ snipabacken.dyndns.org> R'lyeh wgah'nagl fhtagn!
     
    Jorgen Grahn, Aug 20, 2006
    #8
  9. Tom Strickland

    Magnus Lycka Guest

    Jorge Godoy wrote:
    > ;-) And think about security as well.


    I.e. put '.' in the end of your PATH, never in the beginning!
     
    Magnus Lycka, Aug 23, 2006
    #9
    1. Advertising

Want to reply to this thread or ask your own question?

It takes just 2 minutes to sign up (and it's free!). Just click the sign up button to choose a username and then you can ask your own questions on the forum.
Similar Threads
  1. Goblin
    Replies:
    1
    Views:
    8,473
  2. Chris
    Replies:
    1
    Views:
    853
    Roy Johnson
    Oct 28, 2003
  3. Kevin Spencer
    Replies:
    3
    Views:
    3,014
    Kevin Spencer
    Aug 15, 2003
  4. Dave M.
    Replies:
    0
    Views:
    479
    Dave M.
    Nov 18, 2003
  5. =?Utf-8?B?ZmVzdGl2YWxtYW4=?=

    permission denied on an asp that's sending mail

    =?Utf-8?B?ZmVzdGl2YWxtYW4=?=, Jan 26, 2004, in forum: ASP .Net
    Replies:
    1
    Views:
    1,986
    Chris Jackson
    Jan 26, 2004
Loading...

Share This Page