osdir.com


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

Proper shebang for python3



> On 21 Jul 2019, at 08:29, Christian Gollwitzer <auriocus at gmx.de> wrote:
> 
> Am 21.07.19 um 07:31 schrieb Tim Daneliuk:
>> On 7/20/19 6:04 PM, Chris Angelico wrote:
>>> Are you aware of every systemwide command that happens to be
>>> implemented in Python, such that you won't execute any of them while
>>> you have the venv active?
>> No, but this has never been a problem because the newer versions of
>> python tend to be pretty good - within a major release tree - of being
>> backward compatible.  Certainly, if I were running, say, RedHat 4 with
>> a very new version of python in my path first, this could theoretically
>> be an issue.  I've just not run into it.
> 
> It's not about the core language, but these system tools depend on packages, sometimes specialist packages, which might not be available in your venv.

Well said.

The fedora packaging system replaces all shebang lines with the full path to either python2 or python3 on the system
to make sure that scripts installed in the system run as intended and do not break because of the users PATH.

How you think about the shebang lines depends on where the scripts will be used.

If its as an installed system component the exact path is usually the right thing to do.

If it you personal scripts then you may well find /usr/bin/env python3 makes you life
simpler.

For code I'm testing I usual do not depend no shebang lines at all. Often I'm testing
on many python versions. And end up with something like this to test on all interesting python
versions.

for PTYHON in python3.6 python3.7 python3.8
do
    $PYTHON my_script.py
done

Barry