Mailing List Archive

Python and Red Hat Linux 6
When programming in Perl or Python, I am using a header like the
following on an executable file to cause the shell (bash or csh) to run
the scripts as Perl/Python files:
#!/usr/bin/perl for Perl and #!/usr/bin/python for Python. I've
checked and the compilers are located in the appropriate directories. I
keep getting this when I run scripts:
bash: <script name>: command not found. Does Linux support the '#!'
notation in the file header, or do I always have to run the scripts by
explicitly typing in 'perl' or 'python' before the script name?
~Rob~
Python and Red Hat Linux 6 [ In reply to ]
Rob wrote:
>
> When programming in Perl or Python, I am using a header like the
> following on an executable file to cause the shell (bash or csh) to run
> the scripts as Perl/Python files:
> #!/usr/bin/perl for Perl and #!/usr/bin/python for Python. I've
> checked and the compilers are located in the appropriate directories. I
> keep getting this when I run scripts:
> bash: <script name>: command not found. Does Linux support the '#!'
> notation in the file header, or do I always have to run the scripts by
> explicitly typing in 'perl' or 'python' before the script name?
> ~Rob~

Try

!#/usr/bin/env python

instead (don't ask me why, i read it in a FAQ somewhere :-)

--
Brian Pedersen, M.Sc.E.E. /\
DSP Software and Algorithm Development .~. / \ .~.
URL: http://www.danbbs.dk/~kibria/brian/ ~ ~
NOTE: New e-mail address !
Python and Red Hat Linux 6 [ In reply to ]
Rob <vaton@postoffice.pacbell.net> wrote:
> When programming in Perl or Python, I am using a header like the
> following on an executable file to cause the shell (bash or csh) to run
> the scripts as Perl/Python files:
> #!/usr/bin/perl for Perl and #!/usr/bin/python for Python. I've
> checked and the compilers are located in the appropriate directories. I
> keep getting this when I run scripts:
> bash: <script name>: command not found.

did you try:

$ ./scriptname

if this works, check your PATH settings (having "."
in the path is usually considered a bad idea, but it's
your computer ;-)

</F>
Python and Red Hat Linux 6 [ In reply to ]
that sound right.. did you set the file to be executable (chmod?)


Rob wrote:

> When programming in Perl or Python, I am using a header like the
> following on an executable file to cause the shell (bash or csh) to run
> the scripts as Perl/Python files:
> #!/usr/bin/perl for Perl and #!/usr/bin/python for Python. I've
> checked and the compilers are located in the appropriate directories. I
> keep getting this when I run scripts:
> bash: <script name>: command not found. Does Linux support the '#!'
> notation in the file header, or do I always have to run the scripts by
> explicitly typing in 'perl' or 'python' before the script name?
> ~Rob~

--
----------------------------------------------------------------
joeld@anisci.com
Python and Red Hat Linux 6 [ In reply to ]
Yeah, using #!/bin/env/python should help, but Red Hat should support
pound-bang (#!) anyway. You might want to check in with tech support.

Brian Pedersen <brian.pedersen@mail.danbbs.dk> wrote in message
news:379CD5C2.5BA096A2@mail.danbbs.dk...
> Rob wrote:
> >
> > When programming in Perl or Python, I am using a header like the
> > following on an executable file to cause the shell (bash or csh) to run
> > the scripts as Perl/Python files:
> > #!/usr/bin/perl for Perl and #!/usr/bin/python for Python. I've
> > checked and the compilers are located in the appropriate directories. I
> > keep getting this when I run scripts:
> > bash: <script name>: command not found. Does Linux support the '#!'
> > notation in the file header, or do I always have to run the scripts by
> > explicitly typing in 'perl' or 'python' before the script name?
> > ~Rob~
>
> Try
>
> !#/usr/bin/env python
>
> instead (don't ask me why, i read it in a FAQ somewhere :-)
>
> --
> Brian Pedersen, M.Sc.E.E. /\
> DSP Software and Algorithm Development .~. / \ .~.
> URL: http://www.danbbs.dk/~kibria/brian/ ~ ~
> NOTE: New e-mail address !
Python and Red Hat Linux 6 [ In reply to ]
Yes, Linux supports #!. Sounds like /usr/bin/python doesn't exist or
perhaps is not executable.

Bill
Python and Red Hat Linux 6 [ In reply to ]
On Mon, 26 Jul 1999 21:40:18 GMT, Brian Pedersen
<brian.pedersen@mail.danbbs.dk> wrote:
>Try
>
>!#/usr/bin/env python
>
>instead (don't ask me why, i read it in a FAQ somewhere :-)
>--
>Brian Pedersen, M.Sc.E.E.

I have the same problem and this solution won't works. If you type

$ file.py
bash: ./file.py : Command not found

is a normal behaviour. But the correct syntax should be

$ ./file.py

but the output is

bash: file.py : Permission denied

Any good solution?

Marco
Python and Red Hat Linux 6 [ In reply to ]
Kranio wrote:

> I have the same problem and this solution won't works. If you type
>
> $ file.py
> bash: ./file.py : Command not found

file.py is not in your PATH and isn't found.

> $ ./file.py
>
> but the output is
>
> bash: file.py : Permission denied

Now you've specified the path, and file.py is found, but you
haven't made the file executable.

chmod u+x file.py
./file.py

> Any good solution?

man chmod
:)

-------------------------------------------
Tom Bryan
Applied Research Laboratories
University of Texas at Austin
Python and Red Hat Linux 6 [ In reply to ]
On Tue, 27 Jul 1999, Thomas Bryan wrote:

> Kranio wrote:
>
> > I have the same problem and this solution won't works. If you type
> >
> > $ file.py
> > bash: ./file.py : Command not found
>
> file.py is not in your PATH and isn't found.
>

No, no, that would make sense; you get an error like this if file.py is
found and is executable and has a first line of the form

#!/path/to/executable

and /path/to/executable doesn't exist.

HTH
Michael
Python and Red Hat Linux 6 [ In reply to ]
On 26-Jul-99 Brian Pedersen wrote:
> !#/usr/bin/env python
>
> instead (don't ask me why, i read it in a FAQ somewhere :-)


You have to give #! an absolute pathname for it to work. env is
(somewhat) reliably at /usr/bin and is a program used exclusively for
running other programs in certain environments. In this case, it is used
because it will search your path for python rather than requiring it to be
explicit.


----------------------------------
Nathan Clegg
nathan@islanddata.com
Python and Red Hat Linux 6 [ In reply to ]
Excerpts from ext.python: 27-Jul-99 Re: Python and Red Hat Linux 6
Nathan Clegg@islanddata. (501*)

> You have to give #! an absolute pathname for it to work. env is
> (somewhat) reliably at /usr/bin and is a program used exclusively for
> running other programs in certain environments. In this case, it is used
> because it will search your path for python rather than requiring it to be
> explicit.

Of course, it only works if python is on the PATH of the program
executing the script. Personally, I don't find the /usr/bin/env hack
useful.

Bill
Python and Red Hat Linux 6 [ In reply to ]
>>>>> "Bill" == Bill Janssen <janssen@parc.xerox.com> writes:

>> You have to give #! an absolute pathname for it to work. env is
>> (somewhat) reliably at /usr/bin and is a program used exclusively
>> for running other programs in certain environments. In this
>> case, it is used because it will search your path for python
>> rather than requiring it to be explicit.

Bill> Of course, it only works if python is on the PATH of the
Bill> program executing the script. Personally, I don't find the
Bill> /usr/bin/env hack useful.

It used to be more useful when python tended to be in /usr/local/bin
rather than /usr/bin which is now the case on most Linux boxes. The
env hack also has the disadvantage that it doesn't let you pass
through the -O option to the python interpreter (at least under
Linux). This is the case on various other flavours of unix as well,
which is why perl reparses the first line of the perl script to get
the options instead of relying on what it was given as argv.

This topic seems to come up rather regularly. As always, I strongly
suggest people read "man perlrun" and "man tclsh" to get a good
understanding of the pro's and con's of the various methods. Maybe
this is for the FAQ?

- Andrew thought-it-was-already-in-there Snare
--
#!/usr/bin/env python
print(lambda s:s+"("+`s`+")")\
('#!/usr/bin/env python\012print(lambda s:s+"("+`s`+")")\\\012')
print(lambda x:x%`x`)('print(lambda x:x%%`x`)(%s)')
Python and Red Hat Linux 6 [ In reply to ]
Michael Hudson wrote:
>
> On Tue, 27 Jul 1999, Thomas Bryan wrote:
>
> > Kranio wrote:
> >
> > > I have the same problem and this solution won't works. If you type
> > >
> > > $ file.py
> > > bash: ./file.py : Command not found
> >
> > file.py is not in your PATH and isn't found.
> >
>
> No, no, that would make sense; you get an error like this if file.py is
> found and is executable and has a first line of the form
>
> #!/path/to/executable
>
> and /path/to/executable doesn't exist.

I think I may have misread the post and answered somewhat hastily.
The point I was trying to make was:
1. Make sure the file containing the python script is in your PATH
or supply an absolute path to that file.
2. Make sure the #!/path/to/executable actually points to the correct
executable.
3. Make sure the file containing the python script is executable.

On my Red Hat 6.0 system, problems #1 and #2 report an identical
error message. I lost track of the thread, but I meant to suggest
that if one has already checked #2, then he should also check #2.

the-gremlins-have-been-modifying-my-PATH-ly yours
Tom

-------------------------------------------
Tom Bryan
Applied Research Laboratories
University of Texas at Austin
Python and Red Hat Linux 6 [ In reply to ]
Thomas Bryan wrote:
> On my Red Hat 6.0 system, problems #1 and #2 report an identical
> error message. I lost track of the thread, but I meant to suggest
> that if one has already checked #2, then he should also check #2.

ummm...oops....that should be "then he should also check #1"

> the-gremlins-have-been-modifying-my-PATH-ly yours

the-gremlins-have-been-modifying-my-news-posts-ly yours

-------------------------------------------
Tom Bryan
Applied Research Laboratories
University of Texas at Austin
Python and Red Hat Linux 6 [ In reply to ]
Spud wrote:
>
> Yeah, using #!/bin/env/python should help, but Red Hat should support
> pound-bang (#!) anyway. You might want to check in with tech support.
>


Uhmm ... it is not RedHat, but a shell thing, and if #! didn't work,
neither would #!/bin/env/python.

--
Bill Anderson Linux/Unix Administrator, Security Analyst
ESSD (ARC) banderson@boi.hp.com
My opinions are just that; _my_ opinions.
Python and Red Hat Linux 6 [ In reply to ]
Bill Anderson wrote:
> Spud wrote:
> >
> > Yeah, using #!/bin/env/python should help, but Red Hat should support
> > pound-bang (#!) anyway. You might want to check in with tech support.
> >
>
> Uhmm ... it is not RedHat, but a shell thing, and if #! didn't work,
> neither would #!/bin/env/python.

I think you mean

#!/bin/env python

The command you're runing is /bin/env, and you're passing it the
parameter "python". This doesn't work as well as it might because some
systems put env(1) in /usr/bin or /etc (!).

Some systems are known to want a space after the bang so that they can
match the first four bytes as a magic number, but I don't think this
applies to GNU/Linux:

#! /usr/bin/python

On GNU/Linux, the FSSTND ought to specify this: I think /usr/bin/python
should be safe because Python is standard on most distributions these
days.

--
/\\\ Mincom | Martin Pool | martinp@mincom.com
// \\\ | Software Engineer | Phone: +61 7 3303-3333
\\ /// | Mincom Ltd. |
\/// | Teneriffe, Brisbane | Speaking for myself only
Python and Red Hat Linux 6 [ In reply to ]
Martin Pool wrote:
>
> Bill Anderson wrote:
> > Spud wrote:
> > >
> > > Yeah, using #!/bin/env/python should help, but Red Hat should support
> > > pound-bang (#!) anyway. You might want to check in with tech support.
> > >
> >
> > Uhmm ... it is not RedHat, but a shell thing, and if #! didn't work,
> > neither would #!/bin/env/python.
>
> I think you mean
>
> #!/bin/env python

Bou are correct. Must've been a less-than-joyful day at work :-)