how to run python script from Unix Shell?
Peter Hansen
peter at engcorp.com
Thu Sep 6 23:25:46 EDT 2001
David wrote:
>
> Can you help to advise how to run python script from Unix Shell?
> What I am doing is:
> 1)chmod +x script name
> 2)put #!/usr/bin/python at first line
> 3)when I type the script name under Shell,
> the message is:
> bash: Script name command not found.
Note: always cut and paste the *precise* error message
(and preferably the *precise* command you entered)
when you are reporting a problem. This avoids confusion.
In this case, I'm assuming what you saw looked more like:
[phansen]$ test.py
bash: test.py: command not found
If this is the case, you should probably try ./test.py
instead. The shell does not execute files which are not
in one of the directories in the PATH unless you refer
to them explicitly (relative or absolute path). If you
move the file to somewhere in the PATH it should work.
> Actually, it works if I type:
> python "script name"
The other problem could be that your python is not
really in /usr/bin (type "which python" to be sure)
but then your error message would say:
bash: ./test.py: No such file or directory
(This all on Red Hat release 7.1.)
--
----------------------
Peter Hansen, P.Eng.
peter at engcorp.com
More information about the Python-list
mailing list