How to manage python shebang on mixed systems?

Chris Angelico rosuav at gmail.com
Mon Nov 7 16:54:39 EST 2022


On Tue, 8 Nov 2022 at 08:44, Chris Green <cl at isbd.net> wrote:
>
> Barry Scott <barry at barrys-emacs.org> wrote:
> >
> >
> > > On 7 Nov 2022, at 09:28, Chris Green <cl at isbd.net> wrote:
> > >
> > > Chris Green <cl at isbd.net> wrote:
> > >>> 3: with your pseudo "python3" script in place, make all the scripts use
> > >>> the "#!/usr/bin/env python3" shebang suggested above.
> > >>>
> > >> Yes, that sounds a good plan to me, thanks Cameron.
> > >>
> > > Doesn't '#!/usr/bin/env python3' suffer from the same problem as
> > > '#!/usr/bin/python3' in the sense that the env executable might not be
> > > in /usr/bin?
> >
> > env is always available as /usr/bin/env - I think its spec'ed in posix that way.
> >
> > The only reason that things are in /bin are for systems that need a subset of
> > programs to boot the system to point it can mount /usr. env is not going to be
> > needed for that use case.
> >
> Given that the problem system is running a very old Linux I'm not sure
> what chance there is that it's fully posix compliant.
>
> If using "#!/usr/bin/env python3" is a way of avoiding problems if
> python3 isn't in /usr/bin then why is it any better depending on env
> being in /usr/bin.
>
I frequently have python3 in /usr/local/bin instead. Sometimes in
other places, depending on how many of them I've installed and from
where. Using /usr/bin/env python3 ensures that it does the same as the
"python3" command even if there's a venv active.

(And yes, sometimes that's good, sometimes bad.)

ChrisA


More information about the Python-list mailing list