SamCoVT wrote:
I also had to change all references of "python3" to "python" as 3.8.1 did not appear to install a "python3.exe".
Oh, don't do that! You're right that Windows doesn't install a
python3.exe, but
python on Linux is always Python 2, and this will not change soon. (More on this below.)
Linux generally has no more than two system installs of Python present, Python 2 as
python and Python 3 as
python3. Windows, however, may have multiple installs present; these register themselves in the Windows registry during install for use by the Python launcher.
Thus, the correct way to run Python on Windows is via the
Python Launcher for Windows,
py. While
python will run a random version of Python (usually the first one you installed),
py -3 will run the latest version of Python 3 that's available (or fail, even if Python 2 versions are present), which is what you want. But if you're running a script with a Unix shebang (e.g.,
#!/usr/bin/env python3) you can just
py script.py and py will find the right version for you.
As for figuring out if you're on Windows or not, so you know whether to use
python3 or
py, I know you can
check if MSYSTEM is set (to anything) to see if you're running in one of the MSYS2 environments; I presume CygWin has something similar. But I'm not really too familiar with all the details of the various ways of getting Linuxy on Windows. (When I use Windows I just use the MSYS2 stuff, including Bash, that ships with
Git for Windows.) But I'd be interested in knowing how you end up doing the check so that I can update my notes.
BigEd wrote:
(As of very recently, python2 is no longer maintained, so it's become reasonable for 'python' to mean 'python3' - which is not to say that everything everywhere will still work. We've had a long time to make the adjustment, but many of us haven't.)
Actually, that adjustment isn't going to happen for some time, if ever, because though Python 2 is no longer maintained there are still a
lot of older Linux systems out there that define
python to mean Python 2 (and have Python 2 software on them). These are going to take a long time to go away; I know of plenty of systems still running CentOS 5. Those might finally go away soon, but consider that if it took someone ten years to upgrade a server from CentOS 5, it may well be 2028 before they upgrade that Ubuntu 18.04 machine they just installed.
And really, it's just not worth going through a breaking API change (defining
#!/usr/bin/env python to run 3 instead of 2) when we already have working and widespread solutions for both Linux (keep it as it is) and Windows (use
py).