Re: How to manage python shebang on mixed systems?

2022-11-09 Thread Peter J. Holzer
On 2022-11-07 21:27:26 +, Chris Green wrote:
> Barry Scott  wrote:
> > 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.

It doesn't have to be fully posix compliant. Just reasonably 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.

Because env is a standard unix utility which has been in the same place
for 30 years or so and is unlikely to be somewhere else or missing
completely. Python3 OTOH is not a standard unix utility. It may not be
there at all or it may be installed in /usr/local or /opt or even in the
user's home directory.

(Yes, of course "standard unix utilities" may be missing, too. For
example on an embedded system there might only be the bare minimum to
run the application. I even had a redhat system once which didn't have
grep installed.)

(Personally I avoid using env: I don't want my scripts to depend on the
PATH. But that's a different issue.)

hp

-- 
   _  | Peter J. Holzer| Story must make more sense than reality.
|_|_) ||
| |   | h...@hjp.at |-- Charles Stross, "Creative writing
__/   | http://www.hjp.at/ |   challenge!"


signature.asc
Description: PGP signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-08 Thread jak

Il 07/11/2022 20:41, Chris Green ha scritto:

Schachner, Joseph (US)  wrote:

Maybe you can't do this, but I would suggest only running on the Python
3 systems. Refuse to jump through hoops for the Python 2 system. It is
years out of date.


Exactly! That's why I (OP) have only one system where this is a
problem. The system is my hosting provider's cPanel platform which is
running a very old Linux and, as I've said has only python 2.

I can ask for python 3 on their system but I suspect that my voice is
a very tiny one and there are higher priority things to get done.



Perhaps this is because you speak to them about the problems of
compatibility, try to speak to them about power, speed and performance,
instead. ;-D

--
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Thomas Passin

More discussion:

https://unix.stackexchange.com/questions/29608/why-is-it-better-to-use-usr-bin-env-name-instead-of-path-to-name-as-my

On 11/7/2022 5:35 PM, Cameron Simpson wrote:

On 07Nov2022 09:28, Chris Green  wrote:

Chris Green  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?

Wouldn't '#! env python3' be better?


The thing after the shebang needs to be a full path.

"env" is in /usr/bin on damn near everything. I think I had to make a 
symlink on a Solaris system once, but otherwise it has not been a 
problem for me on many different systems for many years.


Cheers,
Cameron Simpson 


--
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Cameron Simpson

On 07Nov2022 09:28, Chris Green  wrote:

Chris Green  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?

Wouldn't '#! env python3' be better?


The thing after the shebang needs to be a full path.

"env" is in /usr/bin on damn near everything. I think I had to make a 
symlink on a Solaris system once, but otherwise it has not been a 
problem for me on many different systems for many years.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Chris Angelico
On Tue, 8 Nov 2022 at 08:44, Chris Green  wrote:
>
> Barry Scott  wrote:
> >
> >
> > > On 7 Nov 2022, at 09:28, Chris Green  wrote:
> > >
> > > Chris Green  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
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Chris Green
Barry Scott  wrote:
> 
> 
> > On 7 Nov 2022, at 09:28, Chris Green  wrote:
> > 
> > Chris Green  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.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Christian Gollwitzer

Am 07.11.22 um 10:28 schrieb Chris Green:

Chris Green  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?

Wouldn't '#! env python3' be better?


Does this even work? I thought that, since the #! is resolved by the 
kernel, an absolute path is required, and that the whole purpose of the 
/usr/bin/env thing is to search the path (because it is universally 
installed in /usr/bin) and to possibly set other environment variables




Christian
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Barry Scott


> On 7 Nov 2022, at 09:28, Chris Green  wrote:
> 
> Chris Green  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.

> 
> Wouldn't '#! env python3' be better?

Barry

> 
> -- 
> Chris Green
> ·
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Chris Green
Schachner, Joseph (US)  wrote:
> Maybe you can't do this, but I would suggest only running on the Python 
> 3 systems. Refuse to jump through hoops for the Python 2 system. It is 
> years out of date. 

Exactly! That's why I (OP) have only one system where this is a
problem. The system is my hosting provider's cPanel platform which is
running a very old Linux and, as I've said has only python 2.

I can ask for python 3 on their system but I suspect that my voice is
a very tiny one and there are higher priority things to get done.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Chris Angelico
On Tue, 8 Nov 2022 at 06:12, Thomas Passin  wrote:
>
> The problem is that some Linux systems - I think - still use Python2 to
> perform various system-related tasks.  When they call "python", they
> need it to be Python2.  If someone has a system like that, they can't
> have the "python" command run Python3.
>

If currently-supported versions of any Linux distributions don't at
least make a python3 command available, I would be very surprised. But
when you don't have root access, it's not easy to install, even from
repositories.

ChrisA
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Thomas Passin
The problem is that some Linux systems - I think - still use Python2 to 
perform various system-related tasks.  When they call "python", they 
need it to be Python2.  If someone has a system like that, they can't 
have the "python" command run Python3.


On 11/7/2022 1:07 PM, Schachner, Joseph (US) wrote:

Maybe you can't do this, but I would suggest only running on the Python 3 
systems.  Refuse to jump through hoops for the Python 2 system.  It is years 
out of date.
It is not hard to upgrade from Python 2 to Python 3.  There is a 2to3 utility, 
and after that there should be very few things you want to manually change.  
Perhaps you could encourage them to upgrade.

--- Joseph S.


Teledyne Confidential; Commercially Sensitive Business Data

-Original Message-
From: Chris Green 
Sent: Monday, November 7, 2022 4:06 AM
To: python-list@python.org
Subject: Re: How to manage python shebang on mixed systems?

Cameron Simpson  wrote:

On 06Nov2022 20:51, jak  wrote:

Il 06/11/2022 11:03, Chris Green ha scritto:

I have a number of python scripts that I run on a mix of systems.  I
have updated them all to run on python 3 but many will also run
quite happily with python 2.  They all have a #!/usr/bin/python3 shebang.


I usually use:

 #!/usr/bin/env python3

This runs the default "python3" from my $PATH, whatever that is,
avoiding a hardwired path to the python3 executable.


Yes, that's probably a good idea, less likely to break than mine.



This works almost everywhere but there is one system where only
python 2 is available (at /usr/bin/python).

I don't have python 2 on any of the systems I manage myself now so a
#!/usr/bin/python shebang will fail.

Is there a neat way of handling this?  I could write a sort of
wrapper script to run via the shebang but that seems overkill to me.


It is overkill. I generally dislike batch editing scripts.

1: do these scripts work on both python2 and python3? It seems like
they would need to.


Yes, they do, they're mostly very simple utility scripts for doing things like 
changing spaces to underscores in filenames and such.
Just putting 'print' parameters in brackets was all that most of them needed to 
work in python 3.



2: write a tiny script _named_ "python3" which invokes python 2. I
keep a personal "~/bin-local" directory for just such per-system
special commands like this.
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.

--
Chris Green
·


--
https://mail.python.org/mailman/listinfo/python-list


RE: How to manage python shebang on mixed systems?

2022-11-07 Thread Schachner, Joseph (US)
Maybe you can't do this, but I would suggest only running on the Python 3 
systems.  Refuse to jump through hoops for the Python 2 system.  It is years 
out of date.
It is not hard to upgrade from Python 2 to Python 3.  There is a 2to3 utility, 
and after that there should be very few things you want to manually change.  
Perhaps you could encourage them to upgrade.

--- Joseph S.


Teledyne Confidential; Commercially Sensitive Business Data

-Original Message-
From: Chris Green  
Sent: Monday, November 7, 2022 4:06 AM
To: python-list@python.org
Subject: Re: How to manage python shebang on mixed systems?

Cameron Simpson  wrote:
> On 06Nov2022 20:51, jak  wrote:
> >Il 06/11/2022 11:03, Chris Green ha scritto:
> >>I have a number of python scripts that I run on a mix of systems.  I 
> >>have updated them all to run on python 3 but many will also run 
> >>quite happily with python 2.  They all have a #!/usr/bin/python3 shebang.
> 
> I usually use:
> 
> #!/usr/bin/env python3
> 
> This runs the default "python3" from my $PATH, whatever that is, 
> avoiding a hardwired path to the python3 executable.
> 
Yes, that's probably a good idea, less likely to break than mine.


> >>This works almost everywhere but there is one system where only 
> >>python 2 is available (at /usr/bin/python).
> >>
> >>I don't have python 2 on any of the systems I manage myself now so a 
> >>#!/usr/bin/python shebang will fail.
> >>
> >>Is there a neat way of handling this?  I could write a sort of 
> >>wrapper script to run via the shebang but that seems overkill to me.
> 
> It is overkill. I generally dislike batch editing scripts.
> 
> 1: do these scripts work on both python2 and python3? It seems like 
> they would need to.

Yes, they do, they're mostly very simple utility scripts for doing things like 
changing spaces to underscores in filenames and such.
Just putting 'print' parameters in brackets was all that most of them needed to 
work in python 3.


> 2: write a tiny script _named_ "python3" which invokes python 2. I 
> keep a personal "~/bin-local" directory for just such per-system 
> special commands like this.
> 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.

--
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Chris Green
Chris Green  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?

Wouldn't '#! env python3' be better?

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Chris Green
Cameron Simpson  wrote:
> On 06Nov2022 20:51, jak  wrote:
> >Il 06/11/2022 11:03, Chris Green ha scritto:
> >>I have a number of python scripts that I run on a mix of systems.  I
> >>have updated them all to run on python 3 but many will also run quite
> >>happily with python 2.  They all have a #!/usr/bin/python3 shebang.
> 
> I usually use:
> 
> #!/usr/bin/env python3
> 
> This runs the default "python3" from my $PATH, whatever that is, 
> avoiding a hardwired path to the python3 executable.
> 
Yes, that's probably a good idea, less likely to break than mine.


> >>This works almost everywhere but there is one system where only
> >>python 2 is available (at /usr/bin/python).
> >>
> >>I don't have python 2 on any of the systems I manage myself now so a
> >>#!/usr/bin/python shebang will fail.
> >>
> >>Is there a neat way of handling this?  I could write a sort of wrapper
> >>script to run via the shebang but that seems overkill to me.
> 
> It is overkill. I generally dislike batch editing scripts.
> 
> 1: do these scripts work on both python2 and python3? It seems like they 
> would need to.

Yes, they do, they're mostly very simple utility scripts for doing
things like changing spaces to underscores in filenames and such.
Just putting 'print' parameters in brackets was all that most of them
needed to work in python 3.


> 2: write a tiny script _named_ "python3" which invokes python 2. I keep 
> a personal "~/bin-local" directory for just such per-system special 
> commands like this.
> 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.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread 2QdxY4RzWzUUiLuE
On 2022-11-07 at 11:56:19 +,
"Weatherby,Gerard"  wrote:

> Write the wrapper script.
> 
> #!/bin/bash
> if [ $(hostname) == "oldystem" ]; then
> exec /usr/bin/python $*
> else
> exec /usr/bin/python2 $*
> fi

Use "$@" (with the quotes) instead of a bare $*.  The former preserves
quoted arguments, while the latter does not.

Also, it's probably more robust to check explcitly for python2 instead
of depending on the hostname.  Renaming hosts isn't a common operation,
but in general, checking for what something *does* or *has* is better
than checking for what it *is* (hey, look:  duck typing!).

Implementing both suggestions yields this:

#! /bin/bash
if [ -x /usr/bin/python2 ]; then
exec /usr/bin/python2 "$@"
else
exec /usr/bin/python "$@"
fi

YMMV.
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Weatherby,Gerard
Write the wrapper script.

#!/bin/bash
if [ $(hostname) == "oldystem" ]; then
exec /usr/bin/python $*
else
exec /usr/bin/python2 $*
fi

From: Python-list  on 
behalf of Chris Green 
Date: Sunday, November 6, 2022 at 3:22 PM
To: python-list@python.org 
Subject: Re: How to manage python shebang on mixed systems?
*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

rbowman  wrote:
> On Sun, 6 Nov 2022 10:03:50 +, Chris Green wrote:
>
>
> > Is there a neat way of handling this?  I could write a sort of wrapper
> > script to run via the shebang but that seems overkill to me.
>
> Can you symlink?

Not really, since the system where there's no python3 is one where I
only have user access.

--
Chris Green
·
--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!gN4FcCAwYqK8bafmF2dr_EB9nahZcdNmU91bHuymdlakU27cNTnIwQ_FckF9PBZlllGnW_vlEjQ$<https://urldefense.com/v3/__https:/mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!gN4FcCAwYqK8bafmF2dr_EB9nahZcdNmU91bHuymdlakU27cNTnIwQ_FckF9PBZlllGnW_vlEjQ$>
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-07 Thread Barry


> On 7 Nov 2022, at 03:15, Mike Dewhirst  wrote:
> 
> On 7/11/2022 6:51 am, jak wrote:
>> Il 06/11/2022 11:03, Chris Green ha scritto:
>>> I have a number of python scripts that I run on a mix of systems.  I
>>> have updated them all to run on python 3 but many will also run quite
>>> happily with python 2.  They all have a #!/usr/bin/python3 shebang.
>>> This works almost everywhere but there is one system where only
>>> python 2 is available (at /usr/bin/python).
>>> I don't have python 2 on any of the systems I manage myself now so a
>>> #!/usr/bin/python shebang will fail.
>>> Is there a neat way of handling this?  I could write a sort of wrapper
>>> script to run via the shebang but that seems overkill to me.
> 
> Can you link the interpreter on each system to the same-named local link and 
> put that in your shebang?
> 
> #!~/scripts/mypython

I do not think ~ works in a #! line. The ~ is handled by the shell, like bash.
But the #! Is handled by the kernel in it exec() handling I recall.

Using /usr/local/bin may be more suitable.

Otherwise you are forced to use the /usr/bin/env method and ensure the PATH 
includes the command to run.

Barry

> 
>> hi,
>> If you can call Python from the shell prompt, then you could remove the
>> path from shebang:
>> #!python
> 
> 
> -- 
> Signed email is an absolute defence against phishing. This email has
> been signed with my private key. If you import my public key you can
> automatically decrypt my signature and be sure it came from me. Just
> ask and I'll send it to you. Your email software can handle signing.
> 
> -- 
> https://mail.python.org/mailman/listinfo/python-list

-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-06 Thread Mike Dewhirst

On 7/11/2022 6:51 am, jak wrote:

Il 06/11/2022 11:03, Chris Green ha scritto:

I have a number of python scripts that I run on a mix of systems.  I
have updated them all to run on python 3 but many will also run quite
happily with python 2.  They all have a #!/usr/bin/python3 shebang.

This works almost everywhere but there is one system where only
python 2 is available (at /usr/bin/python).

I don't have python 2 on any of the systems I manage myself now so a
#!/usr/bin/python shebang will fail.

Is there a neat way of handling this?  I could write a sort of wrapper
script to run via the shebang but that seems overkill to me.



Can you link the interpreter on each system to the same-named local link 
and put that in your shebang?


#!~/scripts/mypython



hi,
If you can call Python from the shell prompt, then you could remove the
path from shebang:

#!python




--
Signed email is an absolute defence against phishing. This email has
been signed with my private key. If you import my public key you can
automatically decrypt my signature and be sure it came from me. Just
ask and I'll send it to you. Your email software can handle signing.



OpenPGP_signature
Description: OpenPGP digital signature
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-06 Thread Weatherby,Gerard



A possible solution is here.

https://superuser.com/questions/815323/can-i-have-a-conditional-shebang

From: Python-list  on 
behalf of jak 
Sent: Sunday, November 6, 2022 2:51:10 PM
To: python-list@python.org 
Subject: Re: How to manage python shebang on mixed systems?

*** Attention: This is an external email. Use caution responding, opening 
attachments or clicking on links. ***

Il 06/11/2022 11:03, Chris Green ha scritto:
> I have a number of python scripts that I run on a mix of systems.  I
> have updated them all to run on python 3 but many will also run quite
> happily with python 2.  They all have a #!/usr/bin/python3 shebang.
>
> This works almost everywhere but there is one system where only
> python 2 is available (at /usr/bin/python).
>
> I don't have python 2 on any of the systems I manage myself now so a
> #!/usr/bin/python shebang will fail.
>
> Is there a neat way of handling this?  I could write a sort of wrapper
> script to run via the shebang but that seems overkill to me.
>

hi,
If you can call Python from the shell prompt, then you could remove the
path from shebang:

#!python

--
https://urldefense.com/v3/__https://mail.python.org/mailman/listinfo/python-list__;!!Cn_UX_p3!ke_gwJrnkkPx4fdk8CkLm6Qd2lmYIl7st4qz7Mmn0G8BerBOEwRWBfm51eFZ-Ut4WCTXTGoUEP5MTWYjmZE$
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-06 Thread Cameron Simpson

On 06Nov2022 20:51, jak  wrote:

Il 06/11/2022 11:03, Chris Green ha scritto:

I have a number of python scripts that I run on a mix of systems.  I
have updated them all to run on python 3 but many will also run quite
happily with python 2.  They all have a #!/usr/bin/python3 shebang.


I usually use:

#!/usr/bin/env python3

This runs the default "python3" from my $PATH, whatever that is, 
avoiding a hardwired path to the python3 executable.



This works almost everywhere but there is one system where only
python 2 is available (at /usr/bin/python).

I don't have python 2 on any of the systems I manage myself now so a
#!/usr/bin/python shebang will fail.

Is there a neat way of handling this?  I could write a sort of wrapper
script to run via the shebang but that seems overkill to me.


It is overkill. I generally dislike batch editing scripts.

1: do these scripts work on both python2 and python3? It seems like they 
would need to.
2: write a tiny script _named_ "python3" which invokes python 2. I keep 
a personal "~/bin-local" directory for just such per-system special 
commands like this.
3: with your pseudo "python3" script in place, make all the scripts use 
the "#!/usr/bin/env python3" shebang suggested above.


Cheers,
Cameron Simpson 
--
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-06 Thread Chris Green
rbowman  wrote:
> On Sun, 6 Nov 2022 10:03:50 +, Chris Green wrote:
> 
> 
> > Is there a neat way of handling this?  I could write a sort of wrapper
> > script to run via the shebang but that seems overkill to me.
> 
> Can you symlink?

Not really, since the system where there's no python3 is one where I
only have user access.

-- 
Chris Green
·
-- 
https://mail.python.org/mailman/listinfo/python-list


Re: How to manage python shebang on mixed systems?

2022-11-06 Thread jak

Il 06/11/2022 11:03, Chris Green ha scritto:

I have a number of python scripts that I run on a mix of systems.  I
have updated them all to run on python 3 but many will also run quite
happily with python 2.  They all have a #!/usr/bin/python3 shebang.

This works almost everywhere but there is one system where only
python 2 is available (at /usr/bin/python).

I don't have python 2 on any of the systems I manage myself now so a
#!/usr/bin/python shebang will fail.

Is there a neat way of handling this?  I could write a sort of wrapper
script to run via the shebang but that seems overkill to me.



hi,
If you can call Python from the shell prompt, then you could remove the
path from shebang:

#!python

--
https://mail.python.org/mailman/listinfo/python-list