RE: Python scripts - /usr/bin/env python3 vs python vs python2.7

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

 




> -----Original Message-----
> From: Sitsofe Wheeler <sitsofe@xxxxxxxxx>
> Sent: Thursday, May 28, 2020 3:20 AM
> To: Elliott, Robert (Servers) <elliott@xxxxxxx>
> Cc: Vincent Fu <vincentfu@xxxxxxxxx>; Rebecca Cran
> <rebecca@xxxxxxxxx>; fio@xxxxxxxxxxxxxxx; Jens Axboe
> <axboe@xxxxxxxxx>
> Subject: Re: Python scripts - /usr/bin/env python3 vs python vs
> python2.7
> 
> > I have been using python a lot recently and also noticed that the
> > /usr/bin/env format is the preferred approach; it works best across
> > linux distros, local installs, and is even recognized by Python in
> > Windows.
> 
> I'm guessing that's only in git for windows style shells? Surely
> native Windows will just look at the extension and then look in the
> registry?

With Python 3.8 installed (as "python", which is how the upstream installer
names it), this is what it does in PowerShell:

PS D:\> type testshe.py                                                                                              #!/usr/bin/env python
print("hello")

PS D:\> type testshe2.py                                                                                             #!/usr/bin/env python2
print("hello")

PS D:\> type testshe3.py                                                                                             #!/usr/bin/env python3
print("hello")

PS D:\> type testshe310.py                                                                                           #!/usr/bin/env python3.10
print("hello")

PS D:\> ./testshe.py; ./testshe2.py; ./testshe3.py; ./testshe310.py
hello
Requested Python version (2) is not installed
hello
Requested Python version (3.10) is not installed

PS D:\> python ./testshe.py; python ./testshe2.py; python ./testshe3.py; python ./testshe310.py
hello
hello
hello
hello

In other words, it checks the shebang version if invoked indirectly,
but ignores it the python script filename is an argument.

In Windows Subsystem for Linux + Ubuntu + python3, where it's installed
as "python3":
/mnt/d$ ./testshe.py; ./testshe2.py; ./testshe3.py; ./testshe310.py
/usr/bin/env: ‘python’: No such file or directory
/usr/bin/env: ‘python2’: No such file or directory
hello
/usr/bin/env: ‘python3.10’: No such file or directory

/mnt/d $ python3 ./testshe.py; python3 ./testshe2.py; python3 ./testshe3.py; python3 ./testshe310.py
hello
hello
hello
hello





[Index of Archives]     [Linux Kernel]     [Linux SCSI]     [Linux IDE]     [Linux USB Devel]     [Video for Linux]     [Linux Audio Users]     [Yosemite News]     [Linux SCSI]

  Powered by Linux