[petsc-dev] #!/usr/bin/env python2?

Toby D. Young tyoung at ippt.gov.pl
Tue Oct 19 08:58:13 CDT 2010

Greetings Jed,

I ran into the python2/python3 problem a couple of months back on my
gentoo box. Since I found no comfortable way to switch to python3, I
switched my default python back to 2 (but that does not answer your

> Since PETSc's use of Python does not work with python3, I think it makes
> sense to put
> #!/usr/bin/env python2
> in all the python files.  Is there any reason not to do this?

I wonder if a simpler approach would be to start the PETSc configure with
a check on the python version? That way one can edit a single file rather
than many and would make future compatibility/development/migration to
python3 easier. It should be possible to check for the existance of
python2 on the system and if so use that as a default.

Something like:

if (python -V gives major number >= 3)
   check for python2
      if (no python2 exists)
         panic and/or vomit on the petsc-user
         use python2
   (do nothing, use python major number <= 3)

Thankfully getting the version number out of python is still the same. I
get this from my gentoo box where both are installed but I fixed python2
to be the favourite (default).

tyoung at wiatr ~ $ python -V
Python 2.6.5
tyoung at wiatr ~ $ python2 -V
Python 2.6.5
tyoung at wiatr ~ $ python3 -V
Python 3.1.2

The check could be done right at the top of configure. I'm not much of a
python writer, but I could try to hack something like that together if
this is a reasonable way forward. There may be even simpler ways of doing
the same thing... I would be happy to try it out for us.

Does that make sense? What do you think?



Toby D. Young
Assistant Professor

Institute of Fundamental Technological Problems
Polish Academy of Sciences
ul Adolfa Pawinskiego 5b
02-106 Warsaw

www:   http://www.ippt.gov.pl/~tyoung
skype: stenografia

More information about the petsc-dev mailing list