Re: simple trick to make dealing with python 2/3 scripts easier

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



On 2012/8/17 Ben Booth <benwbooth@xxxxxxxxx> wrote:
> Lots of python scripts still use #!/usr/bin/python instead of explicitly
> stating which version of python to use. Here's quick trick to make running
> various python version 2 or 3 scripts easier:
>
> remove the /usr/bin/python symlink and replace with this shell script:
>
> #!/usr/bin/env bash
> exec /usr/bin/"${PYTHON:-python3}" "$@"
>
> Now you can set the PYTHON environment variable to be either python2 or
> python3, depending on which version of python the script expects. Just don't
> set PYTHON=python, or you'll get a recursive loop! The only problem with
> this approach is that /usr/bin/python is owned by the python package, so if
> you upgrade the python package it might create problems. Any one know of
> some way to work around this problem?

Run your scripts using "python2 script.py" or use setuptools that
rewrites shebang automatically.

Rémy.


[Index of Archives]     [Linux Wireless]     [Linux Kernel]     [ATH6KL]     [Linux Bluetooth]     [Linux Netdev]     [Kernel Newbies]     [Share Photos]     [IDE]     [Security]     [Git]     [Netfilter]     [Bugtraq]     [Yosemite News]     [MIPS Linux]     [ARM Linux]     [Linux Security]     [Linux RAID]     [Linux ATA RAID]     [Samba]     [Device Mapper]
  Powered by Linux