[Tutor] i can't for the life of me get "#! /usr/bin/env python" or "#!/usr/bin/python" to work
Steve Willoughby
steve at alchemy.com
Wed Oct 21 20:36:08 CEST 2009
On Wed, Oct 21, 2009 at 02:21:23PM -0400, Jason Willis wrote:
> hi everyone,
>
> sorry for the rather boring question but i'm having serious issues getting
> my programs to run from the command line without having to type "python"
> in-front of them. I've tried a lot of different variations on the
> #!/usr/bin/ etc. line and have come up with the following every time:
If ./mycode.py works, then the #! line is fine. It just means that
the directory containing mycode.py is not in your PATH. If you set
up a directory like /usr/local/bin and put mycode.py in it (or rename
it to mycode), and have /usr/local/bin in your path, then you can
just type:
$ mycode
and it will work as expected. Having to type a full (absolute
or relative) path to it (and ./mycode *is* a relative pathname
explicitly saying you want the "mycode" in the current directory)
Generally speaking, while Linux/Unix won't STOP you from putting
"." in your path, it's not a good idea, *especially* for the root
account. Being in a directory which just happens to contain the
names of common commands can be a pain if the system is set to
run whatever out of the current directory.
If the #! line isn't being recognized at all, do the following:
Make sure your file is formatted as a Unix text file (lines ending
with \n, not \r\n).
Also make sure you know the full path to Python, for example:
# which python
/usr/local/bin/python
"Aha! Looks like python is in /usr/local/bin!"
Put that location in your shebang line:
#!/usr/local/bin/python
--
Steve Willoughby | Using billion-dollar satellites
steve at alchemy.com | to hunt for Tupperware.
More information about the Tutor
mailing list