Re: Python executable



"presentt" <presentt@xxxxxxxxx> said:

>Hello,
>
>I'm running Ubuntu Linux 5.04.
>
>I just started teaching myself Python today, and have been reading a
>few things to get started. I came across something in one (namely
>http://docs.python.org/tut/node4.html#SECTION004220000000000000000)
>that confused me a little.
>
>It says:
>
>------------
>
>On BSD'ish Unix systems, Python scripts can be made directly
>executable, like shell scripts, by putting the line
>
>#! /usr/bin/env python
>
>(assuming that the interpreter is on the user's PATH) at the beginning
>of the script and giving the file an executable mode. The "#!" must be
>the first two characters of the file. On some platforms, this first
>line must end with a Unix-style line ending ("\n"), not a Mac OS ("\r")
>or Windows ("\r\n") line ending. Note that the hash, or pound,
>character, "#", is used to start a comment in Python.
>
>The script can be given a executable mode, or permission, using the
>chmod command:
>
>$ chmod +x myscript.py
>
>-----------
>
>So I created a file named helloworld.py, and put in it:
>
>#! /usr/bin/env python
>print "Hello, world!"
>
>and then used
>$ chmod +x helloworld.py
>to set the permissions. Finally, I went to my terminal and typed
>$ helloworld.py
>but I was given the bash: helloworld.py: command not found error.
>
>Can someone tell me
>(1)Am I right in saying that something is directly executable if I can
>enter the filename in the command line and it runs?
>(2)Am I setting up the script to be directly executable correctly?
>and (3)Am I trying to run the directly executable script correctly?
>
>Thanks a lot. I hope this post isn't too hard to follow; I know I'm
>asking a lot.
>
>~~Ted Present
>

[3] cd to the directory that contains helloworld.py, then
./helloworld.py
(When you enter helloworld.py as a command, the shell
searches the PATH for helloworld.py and if it is not
found, it complains. If you tell it that it's in the
current directory, it will get it without searching.)


Relevant Pages

  • Re: perl to python
    ... sed and perl can let you do all that quick command line stuff. ... into a full blown script. ... scripts, call it from the python interpreter, whatever I need. ... If I stick to the traditional unix approach, ...
    (comp.lang.python)
  • Re: newbie question
    ... Python is fun and it's easier to use a real OS to develop the programs, ... Grant it I am a command line junky, ... "The script can be given a executable mode, or permission, using the ... the above seems to me like you are useing windows. ...
    (comp.lang.python)
  • Re: [opensuse] Installation methods
    ... >> Regards, Rajko. ... I downloaded a script yesterday. ... So I should have ran "chmod 777 ... I also ran the chmod command for yet another program I was attempting to ...
    (SuSE)
  • Re: CRON Script not working right.
    ... Change the lines to include the full paths for chown and chmod. ... Here's the gist of the script: ... When I run it from the command line as root it works fine as ... MailScanner thanks transtec Computers for their support. ...
    (freebsd-questions)
  • Re: Module problem
    ... I am writing some simple script, and when I start my script from command ... Do you have more than one version of Python installed? ...
    (comp.lang.python)