Python argparse fails when the script run without preceding py -2 or -3

  argparse, command-line, python, python-3.x, windows

My python code is:


import argparse
parser = argparse.ArgumentParser()
parser.add_argument("-v", "--verbose", help="increase output verbosity",
args = parser.parse_args()
if args.verbose:
    print("verbosity turned on")

My default python is Python 3.7.4 (also python 2 is installed on my PC). When I run this script from Windows command line this way:

py -2

or this way:

py -3

The script works fine. But when I run this way:

I get the next error:

usage: [-h] [-v] error: unrecognized arguments:

Why? I always run all my python scripts without preceding py and it works (they do not include argparse module)

Can you please help – why python script that contains arparse does not run without preceding py?

Source: Windows Questions