Search notes:

Python: Command line options

Command line options are printed with python --help. These are, as of version 3.8.3:
-b Issue warnings about str(bytes_instance), str(bytearray_instance) and comparing bytes/bytearray with str. (-bb: issue errors)
-B Don't write cached (.pyc) files on import (compare with PYTHONDONTWRITEBYTECODE=x and sys.dont_write_bytecode)
-c cmd Program passed in as string (terminates option list)
-d Debug output from parser; also PYTHONDEBUG=x
-E Ignore PYTHON* environment variables (such as for example PYTHONPATH)
-h Prints a help message and exits, same as --help
-i Inspect interactively after running script; forces a prompt even if stdin does not appear to be a terminal; also PYTHONINSPECT=x
-I Isolate Python from the user's environment (implies -E and -s)
-m mod Run library module as a script. (If library module is a directory, runs __main__.py). Terminates option list.
-O Remove assert and __debug__-dependent statements; add .opt-1 before .pyc extension; also PYTHONOPTIMIZE=x
-OO Do -O changes and also discard docstrings; add .opt-2 before .pyc extension
-P
-q Don't print version and copyright messages on interactive startup
-s Don't add user site directory to sys.path. See also PYTHONNOUSERSITE
-S Don't imply import site on initialization (see also <install-root>/Lib/site.py)
-u Force the stdout and stderr streams to be unbuffered; this option has no effect on stdin; also PYTHONUNBUFFERED=x
-v Verbose (trace import statements. See also PYTHONVERBOSE=x which can be supplied multiple times to increase verbosity
-V Print the Python version number and exit. Same as --version. Prints more information about the build if given twice.
-W arg Warning control; arg is action:message:category:module:lineno. Compare with PYTHONWARNINGS=arg
-x Skip first line of source, allowing use of non-Unix forms of #!cmd
-X opt Set implementation-specific option. See below for possible values of opt.
The values of the used command line options can be queried at run time using sys.flags.

-X options

-X faulthandler enable faulthandler
-X showrefcount output the total reference count and number of used memory blocks when the program finishes or after each statement in the interactive interpreter. This only works on debug builds
-X tracemalloc start tracing Python memory allocations using the tracemalloc module. By default, only the most recent frame is stored in a traceback of a trace. Use -X tracemalloc=NFRAME to start tracing with a traceback limit of NFRAME frames
-X showalloccount output the total count of allocated objects for each type when the program finishes. This only works when Python was built with COUNT_ALLOCS defined
-X importtime show how long each import takes. It shows module name, cumulative time (including nested imports) and self time (excluding nested imports). Note that its output may be broken in multi-threaded application. Typical usage is python3 -X importtime -c 'import asyncio'
-X dev enable CPython's development model, introducing additional runtime checks which are too expensive to be enabled by default.
-X utf8 enable UTF-8 mode for operating system interfaces, overriding the default locale-aware mode. -X utf8=0 explicitly disables UTF-8 mode, even when it would otherwise activate automatically.
-X pycache_prefix=PATH enable writing .pyc files to a parallel tree rooted at the given directory instead of to the code tree. See also sys.pycache_prefix.
The values of the -X options can be queried at run time using sys._xoptions.

See also

sys.argv

Index