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.
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.
On Sun, 6 Nov 2022 10:03:50 +0000, 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?
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.
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.
On 7 Nov 2022, at 03:15, Mike Dewhirst <miked@dewhirst.com.au> 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
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
On 06Nov2022 20:51, jak <nospam@please.ty> 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.
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.
On Sun, 6 Nov 2022 10:03:50 +0000, 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?
Write the wrapper script.
#!/bin/bash
if [ $(hostname) == "oldystem" ]; then
exec /usr/bin/python $*
else
exec /usr/bin/python2 $*
fi
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 <cl@isbd.net>
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 <cs@cskk.id.au> wrote:
On 06Nov2022 20:51, jak <nospam@please.ty> wrote:Yes, that's probably a good idea, less likely to break than mine.
Il 06/11/2022 11:03, Chris Green ha scritto:I usually use:
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. >>
#!/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.
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. IYes, that sounds a good plan to me, thanks Cameron.
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.
--
Chris Green
·
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.
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.
Chris Green <cl@isbd.net> wrote:
Doesn't '#!/usr/bin/env python3' suffer from the same problem as '#!/usr/bin/python3' in the sense that the env executable might not be3: with your pseudo "python3" script in place, make all the scripts useYes, that sounds a good plan to me, thanks Cameron.
the "#!/usr/bin/env python3" shebang suggested above.
in /usr/bin?
Wouldn't '#! env python3' be better?
On 7 Nov 2022, at 09:28, Chris Green <cl@isbd.net> wrote:
Chris Green <cl@isbd.net> wrote:
Doesn't '#!/usr/bin/env python3' suffer from the same problem as '#!/usr/bin/python3' in the sense that the env executable might not be3: 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.
in /usr/bin?
Wouldn't '#! env python3' be better?
--
Chris Green
·
--
https://mail.python.org/mailman/listinfo/python-list
Barry Scott <barry@barrys-emacs.org> wrote:
On 7 Nov 2022, at 09:28, Chris Green <cl@isbd.net> wrote:
Chris Green <cl@isbd.net> wrote:
Doesn't '#!/usr/bin/env python3' suffer from the same problem as '#!/usr/bin/python3' in the sense that the env executable might not be3: 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.
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.
On 7 Nov 2022, at 09:28, Chris Green <cl@isbd.net> wrote:
Chris Green <cl@isbd.net> wrote:
Doesn't '#!/usr/bin/env python3' suffer from the same problem as '#!/usr/bin/python3' in the sense that the env executable might not be3: 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.
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.
On 07Nov2022 09:28, Chris Green <cl@isbd.net> wrote:
Chris Green <cl@isbd.net> wrote:
Doesn't '#!/usr/bin/env python3' suffer from the same problem as3: with your pseudo "python3" script in place, make all the scriptsuse
the "#!/usr/bin/env python3" shebang suggested above.Yes, that sounds a good plan to me, thanks Cameron.
'#!/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 <cs@cskk.id.au>
Chris Green <cl@isbd.net> wrote:
Doesn't '#!/usr/bin/env python3' suffer from the same problem as >'#!/usr/bin/python3' in the sense that the env executable might not be3: with your pseudo "python3" script in place, make all the scripts useYes, that sounds a good plan to me, thanks Cameron.
the "#!/usr/bin/env python3" shebang suggested above.
in /usr/bin?
Wouldn't '#! env python3' be better?
Schachner, Joseph (US) <Joseph.Schachner@teledyne.com> 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.
Barry Scott <barry@barrys-emacs.org> 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.
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.
Sysop: | Keyop |
---|---|
Location: | Huddersfield, West Yorkshire, UK |
Users: | 546 |
Nodes: | 16 (2 / 14) |
Uptime: | 39:53:41 |
Calls: | 10,392 |
Files: | 14,064 |
Messages: | 6,417,198 |