Command-Line Options

Command lines are used to launch Python programs from a system shell prompt. Command-line options intended for Python itself appear before the specification of the program code to be run. Options intended for the code to be run appear after the program specification. Command lines have the following format:

python [option*]
  [ scriptfilename | -c command | -m module | - ] [arg*]

Python Options


Issues warnings for calling str() with a bytes or bytearray object, and comparing a bytes or bytearray with a str. Option -bb issues errors instead.


Do not write .pyc or .pyo byte-code files on imports.


Turns on parser debugging output (for developers of the Python core).


Ignores Python environment variables described ahead (such as PYTHONPATH).


Prints help message and exit.


Enters interactive mode after executing a script. Useful for postmortem debugging.


Optimizes generated byte-code (create and use .pyo byte-code files). Currently yields a minor performance improvement.


Operates like -O, the previous option, but also removes docstrings from byte-code.


Do not add the user site directory to the sys.path module search path.


Do not imply “import site” on initialization.


Forces stdout and stderr to be unbuffered and binary.


Prints a message each time a module is initialized, showing the place from which it is loaded; repeats this flag for more verbose output.


Prints Python version number and exit.

-W arg

Functions as warning control; arg takes the form action:

Get Python Pocket Reference, 4th Edition now with O’Reilly online learning.

O’Reilly members experience live online training, plus books, videos, and digital content from 200+ publishers.