[Tutor] hello.py: line 1: print: command not found
steve
unseeneasy at yahoo.com
Tue Aug 12 07:48:09 CEST 2008
Hi
In order to execute python script by fedora terminal ; insert #! /bin/env python as the first line in the script.
Python scripts end with a file extension of .py, as
indicated above.
It is also possible in Unix to automatically launch the Python
interpreter without explicitly invoking it by name from the command line. If you
are using any Unix-flavored system, you can use the shell-launching ("sh-bang")
first line of your program:
#!/usr/local/bin/pythonThis may futher help Source Core Python Programming
The file path, the part that follows the #!, is the full path
location of the Python interpreter. As we mentioned before, it is usually
installed in /usr/local/bin or /usr/bin. If not, be sure to
get the exact pathname correct so that you can run your Python scripts.
Pathnames that are not correct will result in the familiar Command not
found error message.
As a preferred alternative, many Unix systems have a command
named env, installed in either /bin or /usr/bin,
which will look for the Python interpreter in your path. If you have
env, your startup line can be changed to something like this:
#!/usr/bin/env python
or, if your env is located in /bin,
#!/bin/env python
env is useful when you either do not know exactly
where the Python executable is located, or if it changes location often, yet
still remains available via your directory path. Once you add the proper startup
directive to the beginning of your script, it becomes directly executable, and
when invoked, loads the Python interpreter first, then runs your script. As we
mentioned before, Python no longer has to be invoked explicitly from the
command. You only need the script name:
$ script.py
-------------- next part --------------
An HTML attachment was scrubbed...
URL: <http://mail.python.org/pipermail/tutor/attachments/20080811/2ec04fa5/attachment.htm>
More information about the Tutor
mailing list