> command -v $pyimpls > /dev/null && echo Using: $pyimpl && exec $pyimpl "$@"
As Lisandro noted below, command -v would have to be swapped out since it also picks up aliases and doesn’t error out. Also shouldn’t the final command sequence be “$pyimpl $0 $@“ so that it runs the configure script it was passed? >> BTW, Are you aware of the behavior of `command -v` with shell aliases? >> >> $ alias python=python3 >> $ command -v python >> alias python='python3' Best regards, Jacob Faibussowitsch (Jacob Fai - booss - oh - vitch) Cell: (312) 694-3391 > On Apr 18, 2020, at 1:53 PM, Satish Balay <[email protected]> wrote: > > I guess this is an alternate way to implement this logic.. > > diff --git a/configure b/configure > index 4538314871..8dddfed05d 100755 > --- a/configure > +++ b/configure > @@ -1,4 +1,4 @@ > -#!/usr/bin/env python > +#!./python-detect > > import sys, os > > diff --git a/python-detect b/python-detect > new file mode 100755 > index 0000000000..1fdfe795c8 > --- /dev/null > +++ b/python-detect > @@ -0,0 +1,6 @@ > +#!/bin/sh > +for pyimpl in python3 python2 python ; do > + command -v $pyimpls > /dev/null && echo Using: $pyimpl && exec $pyimpl > "$@" > +done > +echo “Could not locate python! Please have python3 python2 or python in PATH > +exit 2 > > > Satish > > On Fri, 17 Apr 2020, Jacob Faibussowitsch wrote: > >> Hello All, >> >> I use an Ubuntu docker image based on jedbrown/mpich-ccache and ran into the >> following error (Dockerfile attached as well). >> >> If in a user only has python3 installed and not python2 then /usr/bin/python >> doesn’t exist. Given that python2 has gone the way of the dodo perhaps petsc >> should be looking for python3 over python2. This is a somewhat funky but >> functioning implementation that replaces the shebang line in configure that >> I have been using to default to python3. I don’t know how portable it is >> however, I believe “command" is not universally available in every shell? >> >> #!/bin/sh >> >> # “”” is comment in python, and : is noop in shell so this configure can be >> run as ./configure and python2.7 ./configure >> """:" >> >> # Find the right python implementation, check by sending it on over to dave >> for pyimpls in python3 python2 python /usr/bin/python /usr/bin/env python ; >> do >> command -v > /dev/null $pyimpls && exec $pyimpls $0 "$@“ >> done >> >> # Error code in case things go awry >> >> Echo “PYTHON NOT FOUND” >2 >> >> exit 2 >> >> ":""" >> >> if sys.version_info < (2,6) or (sys.version_info >= (3,0) and >> sys.version_info < (3,4)): >> >> print('************************************************************************') >> print('* Python version 2.6+ or 3.4+ is required to run ./configure >> *') >> print('* Try: "python2.7 ./configure" or "python3 ./configure" >> *') >> >> print('************************************************************************') >> sys.exit(4) >> >> sys.path.insert(0, os.path.abspath('config')) >> import configure >> configure.petsc_configure([]) >> >> >> Best regards, >> >> Jacob Faibussowitsch >> (Jacob Fai - booss - oh - vitch) >> Cell: (312) 694-3391 >> >>
