[petsc-dev] Configure won't find python
Satish Balay
balay at mcs.anl.gov
Fri Apr 17 21:06:44 CDT 2020
> > Given that python2 has gone the way of the dodo perhaps petsc should be looking for python3 over python2.
I'm not sure what would be common across distros/OSes wrt /usr/bin/python - one shouldn't assume this is always python2 [and that it won't exist for python3 only installs]
I have:
balay at sb /home/balay
$ /usr/bin/python --version
Python 3.7.6
Satish
On Fri, 17 Apr 2020, Jacob Faibussowitsch wrote:
> > And what if someone is running on a (perhaps old) Linux distro that does not have python3 installed by default?
>
> The idea would be to find both but prefer python3, but that’s infeasible inside configure without a separate pre-configure configure to write “configure.py" or virtual-env.
>
> > for pyimpls in python3 python2 python /usr/bin/python /usr/bin/env python ; do
> > command -v > /dev/null $pyimpls && exec $pyimpls $0 "$@“
>
> > And there you have, you are trying to check for '/usr/bin/env python', but the shell code you wrote will not work the way you are expecting.
> > Also, unless you are running on a funny environment that does not have /usr/bin/ in $PATH, the trial for 'python' should be enough, and the /usr/bin/python /usr/bin/env python look redundant. Am I missing something?
>
> This line checks if pyimpls exists in order, and then runs pyimpls ./configure so if any of the previous pyimpls exist then it doesn’t check the rest. The last “ should be a regular quotation mark. If it finds a working python it runs configure once then exits, instead of continuing through the rest of the list.
>
> > "Echo" ? Are you really running this on Ubuntu?
>
> Auto-correct strikes again :(. It is “echo” in my script.
>
> > BTW, Are you aware of the behavior of `command -v` with shell aliases?
>
> No, this is a good point you bring up. I tried using the option -p from the manpage but that also doesn’t seem to skip aliases. Not sure how this can be addressed, seems like escaping pyimpls using \ or ‘ or “ doesn’t fix this either...
>
> > -p use a default value for PATH that is guaranteed to find all of
> > the standard utilities
>
> To be clear I’m not saying my script is a change petsc should adopt, hence no MR. It is a hack and a half, and likely doesn’t work on some of the other shells as well as a whole host of portability problems. It's more-so to foster discussion, and see if anyone else has a cleaner automatic form.
>
> Best regards,
>
> Jacob Faibussowitsch
> (Jacob Fai - booss - oh - vitch)
> Cell: (312) 694-3391
>
> > On Apr 17, 2020, at 4:21 PM, Lisandro Dalcin <dalcinl at gmail.com> wrote:
> >
> >
> >
> > On Fri, 17 Apr 2020 at 20:41, Jacob Faibussowitsch <jacob.fai at gmail.com <mailto:jacob.fai at gmail.com>> 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.
> >
> > And what if someone is running on a (perhaps old) Linux distro that does not have python3 installed by default?
> >
> > 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
> > """:"
> >
> > This kind of trickery may be fragile...
> >
> > # 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
> >
> > And there you have, you are trying to check for '/usr/bin/env python', but the shell code you wrote will not work the way you are expecting.
> > Also, unless you are running on a funny environment that does not have /usr/bin/ in $PATH, the trial for 'python' should be enough, and the /usr/bin/python /usr/bin/env python look redundant. Am I missing something?
> >
> > command -v > /dev/null $pyimpls && exec $pyimpls $0 "$@“
> >
> > And the last quote the line above is likely wrong, it is an unicode character.
> >
> > done
> > # Error code in case things go awry
> > Echo “PYTHON NOT FOUND” >2
> >
> > "Echo" ? Are you really running this on Ubuntu?
> > Or you just hacked in on macOS and assumed that it will work everywhere?
> >
> > BTW, Are you aware of the behavior of `command -v` with shell aliases?
> >
> > $ alias python=python3
> > $ command -v python
> > alias python='python3'
> >
> >
> > --
> > Lisandro Dalcin
> > ============
> > Research Scientist
> > Extreme Computing Research Center (ECRC)
> > King Abdullah University of Science and Technology (KAUST)
> > http://ecrc.kaust.edu.sa/ <http://ecrc.kaust.edu.sa/>
>
>
More information about the petsc-dev
mailing list