Permission Denied

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • Tom Strickland

    #1

    Permission Denied

    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
  • hiaips

    #2
    Re: Permission Denied


    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?

    Comment

    • AlbaClause

      #3
      Re: Permission Denied

      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.

      Comment

      • Lawrence D'Oliveiro

        #4
        Re: Permission Denied

        In message <cPRFg.1547$dB. 1365@read2.cgoc able.net>, 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.

        Comment

        • AlbaClause

          #5
          Re: Permission Denied

          Lawrence D'Oliveiro wrote:
          In message <cPRFg.1547$dB. 1365@read2.cgoc able.net>, 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.

          Comment

          • Stargaming

            #6
            Re: Permission Denied

            AlbaClause schrieb:
            Lawrence D'Oliveiro wrote:
            >
            >
            >>In message <cPRFg.1547$dB. 1365@read2.cgoc able.net>, 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
            ../yourpythonscrip t 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
            --

            Comment

            • Jorge Godoy

              #7
              Re: Permission Denied

              Stargaming <stargaming@gma il.comwrites:
              In the most cases, PATH is preconfigured to include "." (. is the current
              directory as .. is the parent one). You can use ./yourpythonscrip t 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 <jgodoy@gmail.c om>

              Comment

              • Jorgen Grahn

                #8
                Re: Permission Denied

                On Sun, 20 Aug 2006 10:35:31 -0300, Jorge Godoy <jgodoy@gmail.c omwrote:
                Stargaming <stargaming@gma il.comwrites:
                >
                >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 ./yourpythonscrip t 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.dyn dns.org R'lyeh wgah'nagl fhtagn!

                Comment

                • Magnus Lycka

                  #9
                  Re: Permission Denied

                  Jorge Godoy wrote:
                  ;-) And think about security as well.
                  I.e. put '.' in the end of your PATH, never in the beginning!

                  Comment

                  Working...