[Date Prev][Date Next] [Thread Prev][Thread Next] [Date Index] [Thread Index]

Re: shebang lines for Python scripts

Apologies for reviving this thread.  It's recently come up in relation to
other discussions I've had and I did a grep over s/usr/bin to find instances
where "/usr/bin/env python" was being used.  Stefano reminded me of this
thread, and when I went back and re-read it, I noticed there wasn't resolution
on all the issues.

On Mar 04, 2011, at 11:23 PM, Piotr Ożarowski wrote:

>any objections to change all shebangs (that do not match
>/usr/bin/python\d(\.\d+) but do math .+python.* regexp) to
>/usr/bin/python¹ in dh_python2 and to /usr/bin/python3 in
>(+ an option to disable this behaviour in both helpers)
>if yes, should options (-OO, etc.) be removed as well?
>[¹] or /usr/bin/python2, depends on PEP 394 status

As a reminder, the issue is that, in development (i.e. upstream) packages,
it's perfectly fine to use "/usr/bin/env python" on the shebang line.
However, I feel strongly that *installed* Python scripts, should never use
this, and instead should use "/usr/bin/python" or possibly

(Stefano brought up a legitimate case where this could prove inconvenient, but
I think it's more important to have a functioning system :).

There were two good proposals in the thread:

 - Debian Python policy should be stronger in its recommendation to use
   /usr/bin/python or /usr/bin/pythonX.Y in the shebang line instead of
   /usr/bin/env python.

 - dh_python{2,3} should rewrite the shebang lines by default, with an option
   to disable that.

I just had a look at D-P policy $1.4.2 and it is stronger now than what Scott
quoted back in March 2011.  Here's what it says now:

1.4.2. Interpreter Location

     The preferred specification for the Python interpreter is
     `/usr/bin/python' or `/usr/bin/python<X>.<Y>'.  This ensures that a
     Debian installation of python is used and all dependencies on
     additional python modules are met.

     Maintainers should not override the Debian Python interpreter using
     `/usr/bin/env python' or `/usr/bin/env python<X>.<Y>'.  This is not
     advisable as it bypasses Debian's dependency checking and makes the
     package vulnerable to incomplete local installations of python.

I like this.  It strikes the right balance, and strongly discourages using

On the second point, I don't think Piotr ever implemented shebang line
rewriting.  I think it would be a good idea to have the helpers help you
conform to D-P policy, so I support adding a feature to dh_python{2,3} to do
this, with an option to disable it.

Of course, this won't help packages that don't use the helpers.  They'll still
do the wrong thing unless the packager takes action.  But at least we can
point to the rationale in D-P policy, and this thread to explain why
/usr/bin/env is usually a bad idea.


Attachment: signature.asc
Description: PGP signature

Reply to: