1PYTHON(1)                   General Commands Manual                  PYTHON(1)
2
3
4

NAME

6       python  - an interpreted, interactive, object-oriented programming lan‐
7       guage
8

SYNOPSIS

10       python [ -B ] [ -b ] [ -d ] [ -E ] [ -h ] [ -i ] [ -I ]
11              [ -m module-name ] [ -q ] [ -O ] [ -OO ] [ -s ] [ -S ] [ -u ]
12              [ -v ] [ -V ] [ -W argument ] [ -x ] [ -X option ] [ -?  ]
13              [ --check-hash-based-pycs default | always | never ]
14              [ -c command | script | - ] [ arguments ]
15

DESCRIPTION

17       Python is an interpreted, interactive, object-oriented programming lan‐
18       guage  that  combines  remarkable power with very clear syntax.  For an
19       introduction to programming in Python, see the  Python  Tutorial.   The
20       Python  Library  Reference  documents built-in and standard types, con‐
21       stants, functions and modules.  Finally, the  Python  Reference  Manual
22       describes  the  syntax  and  semantics of the core language in (perhaps
23       too) much detail.  (These documents may be located via the INTERNET RE‐
24       SOURCES below; they may be installed on your system as well.)
25
26       Python's basic power can be extended with your own modules written in C
27       or C++.  On most  systems  such  modules  may  be  dynamically  loaded.
28       Python is also adaptable as an extension language for existing applica‐
29       tions.  See the internal documentation for hints.
30
31       Documentation for installed Python modules and packages can  be  viewed
32       by running the pydoc program.
33

COMMAND LINE OPTIONS

35       -B     Don't  write .pyc files on import. See also PYTHONDONTWRITEBYTE‐
36              CODE.
37
38       -b     Issue  warnings  about  str(bytes_instance),   str(bytearray_in‐
39              stance)  and comparing bytes/bytearray with str. (-bb: issue er‐
40              rors)
41
42       -c command
43              Specify the command to execute (see next section).  This  termi‐
44              nates the option list (following options are passed as arguments
45              to the command).
46
47       --check-hash-based-pycs mode
48              Configure how Python evaluates the up-to-dateness of  hash-based
49              .pyc files.
50
51       -d     Turn  on  parser debugging output (for expert only, depending on
52              compilation options).
53
54       -E     Ignore environment variables like PYTHONPATH and PYTHONHOME that
55              modify the behavior of the interpreter.
56
57       -h ,  -? ,  --help
58              Prints the usage for the interpreter executable and exits.
59
60       -i     When  a  script  is passed as first argument or the -c option is
61              used, enter interactive mode after executing the script  or  the
62              command.  It does not read the $PYTHONSTARTUP file.  This can be
63              useful to inspect global variables  or  a  stack  trace  when  a
64              script raises an exception.
65
66       -I     Run  Python  in  isolated  mode. This also implies -E and -s. In
67              isolated mode sys.path contains neither the  script's  directory
68              nor  the user's site-packages directory. All PYTHON* environment
69              variables are ignored, too.  Further restrictions may be imposed
70              to prevent the user from injecting malicious code.
71
72       -m module-name
73              Searches  sys.path for the named module and runs the correspond‐
74              ing .py file as a script. This terminates the option list  (fol‐
75              lowing options are passed as arguments to the module).
76
77       -O     Remove  assert  statements and any code conditional on the value
78              of __debug__; augment the filename for compiled (bytecode) files
79              by adding .opt-1 before the .pyc extension.
80
81       -OO    Do  -O and also discard docstrings; change the filename for com‐
82              piled (bytecode) files by adding .opt-2 before the  .pyc  exten‐
83              sion.
84
85       -q     Do  not print the version and copyright messages. These messages
86              are also suppressed in non-interactive mode.
87
88       -s     Don't add user site directory to sys.path.
89
90       -S     Disable the import of the module site and the site-dependent ma‐
91              nipulations of sys.path that it entails.  Also disable these ma‐
92              nipulations if site is explicitly imported later.
93
94       -u     Force the stdout and stderr streams to be unbuffered.  This  op‐
95              tion has no effect on the stdin stream.
96
97       -v     Print  a  message each time a module is initialized, showing the
98              place (filename or built-in module) from  which  it  is  loaded.
99              When  given twice, print a message for each file that is checked
100              for when searching for a module.  Also provides  information  on
101              module cleanup at exit.
102
103       -V ,  --version
104              Prints  the  Python  version number of the executable and exits.
105              When given twice, print more information about the build.
106
107
108       -W argument
109              Warning control. Python's warning machinery  by  default  prints
110              warning messages to sys.stderr.
111
112              The  simplest settings apply a particular action unconditionally
113              to all warnings emitted by a process (even those that are other‐
114              wise ignored by default):
115
116                -Wdefault  # Warn once per call location
117                -Werror    # Convert to exceptions
118                -Walways   # Warn every time
119                -Wmodule   # Warn once per calling module
120                -Wonce     # Warn once per Python process
121                -Wignore   # Never warn
122
123              The  action  names  can be abbreviated as desired and the inter‐
124              preter will resolve them to the appropriate action name. For ex‐
125              ample, -Wi is the same as -Wignore .
126
127              The  full  form  of  argument  is:  action:message:category:mod‐
128              ule:lineno
129
130              Empty fields match all values;  trailing  empty  fields  may  be
131              omitted.  For  example -W ignore::DeprecationWarning ignores all
132              DeprecationWarning warnings.
133
134              The action field is as explained above but only applies to warn‐
135              ings that match the remaining fields.
136
137              The  message field must match the whole printed warning message;
138              this match is case-insensitive.
139
140              The category field matches the warning category  (ex:  "Depreca‐
141              tionWarning"). This must be a class name; the match test whether
142              the actual warning category of the message is a subclass of  the
143              specified warning category.
144
145              The module field matches the (fully-qualified) module name; this
146              match is case-sensitive.
147
148              The lineno field matches the line number, where zero matches all
149              line numbers and is thus equivalent to an omitted line number.
150
151              Multiple  -W  options  can be given; when a warning matches more
152              than one option, the action for the last matching option is per‐
153              formed.  Invalid  -W options are ignored (though, a warning mes‐
154              sage is printed about invalid options when the first warning  is
155              issued).
156
157              Warnings  can  also be controlled using the PYTHONWARNINGS envi‐
158              ronment variable and from within  a  Python  program  using  the
159              warnings  module.   For  example,  the warnings.filterwarnings()
160              function can be used to use a regular expression on the  warning
161              message.
162
163
164       -X option
165              Set  implementation  specific  option. The following options are
166              available:
167
168                  -X faulthandler: enable faulthandler
169
170                  -X showrefcount: output the total reference count and number
171              of used
172                      memory  blocks  when  the program finishes or after each
173              statement in the
174                      interactive interpreter. This only works on debug builds
175
176                  -X tracemalloc: start tracing Python memory allocations  us‐
177              ing the
178                      tracemalloc  module.  By  default,  only the most recent
179              frame is stored in a
180                      traceback of a trace. Use -X tracemalloc=NFRAME to start
181              tracing with a
182                      traceback limit of NFRAME frames
183
184                  -X  importtime:  show  how  long each import takes. It shows
185              module name,
186                      cumulative time (including nested imports) and self time
187              (excluding
188                      nested  imports).  Note that its output may be broken in
189              multi-threaded
190                      application. Typical usage is python3 -X  importtime  -c
191              'import asyncio'
192
193                  -X dev: enable CPython's "development mode", introducing ad‐
194              ditional runtime
195                      checks which are too expensive to be enabled by default.
196              It will not be
197                      more  verbose  than  the default if the code is correct:
198              new warnings are
199                      only emitted when an issue is detected.  Effect  of  the
200              developer mode:
201                         * Add default warning filter, as -W default
202                         *  Install  debug hooks on memory allocators: see the
203              PyMem_SetupDebugHooks()
204                           C function
205                         * Enable the faulthandler module to dump  the  Python
206              traceback on a crash
207                         * Enable asyncio debug mode
208                         * Set the dev_mode attribute of sys.flags to True
209                         * io.IOBase destructor logs close() exceptions
210
211                  -X  utf8: enable UTF-8 mode for operating system interfaces,
212              overriding the default
213                      locale-aware mode. -X utf8=0 explicitly  disables  UTF-8
214              mode (even when it would
215                      otherwise  activate  automatically).  See PYTHONUTF8 for
216              more details
217
218                  -X pycache_prefix=PATH: enable writing .pyc files to a  par‐
219              allel tree rooted at the
220                      given directory instead of to the code tree.
221
222                  -X  warn_default_encoding: enable opt-in EncodingWarning for
223              'encoding=None'
224
225                  -X int_max_str_digits=number: limit the  size  of  int<->str
226              conversions.
227                     This  helps  avoid denial of service attacks when parsing
228              untrusted data.
229                     The default  is  sys.int_info.default_max_str_digits.   0
230              disables.
231
232
233       -x     Skip  the  first line of the source.  This is intended for a DOS
234              specific hack only.  Warning: the line numbers in error messages
235              will be off by one!
236

INTERPRETER INTERFACE

238       The interpreter interface resembles that of the UNIX shell: when called
239       with standard input connected to a tty device, it prompts for  commands
240       and  executes  them  until an EOF is read; when called with a file name
241       argument or with a file as standard input,  it  reads  and  executes  a
242       script  from  that  file;  when called with -c command, it executes the
243       Python statement(s) given as command.  Here command may contain  multi‐
244       ple  statements  separated by newlines.  Leading whitespace is signifi‐
245       cant in Python statements!  In non-interactive mode, the  entire  input
246       is parsed before it is executed.
247
248       If  available,  the script name and additional arguments thereafter are
249       passed to the script in the Python variable sys.argv, which is  a  list
250       of  strings (you must first import sys to be able to access it).  If no
251       script name is given, sys.argv[0] is an empty string; if  -c  is  used,
252       sys.argv[0] contains the string '-c'.  Note that options interpreted by
253       the Python interpreter itself are not placed in sys.argv.
254
255       In interactive mode, the primary prompt is  `>>>';  the  second  prompt
256       (which  appears  when a command is not complete) is `...'.  The prompts
257       can be changed by assignment to sys.ps1 or  sys.ps2.   The  interpreter
258       quits  when  it  reads an EOF at a prompt.  When an unhandled exception
259       occurs, a stack trace is printed and control  returns  to  the  primary
260       prompt;  in  non-interactive mode, the interpreter exits after printing
261       the stack trace.  The interrupt signal raises the KeyboardInterrupt ex‐
262       ception;  other  UNIX  signals  are  not caught (except that SIGPIPE is
263       sometimes ignored, in favor of the IOError exception).  Error  messages
264       are written to stderr.
265

FILES AND DIRECTORIES

267       These are subject to difference depending on local installation conven‐
268       tions; ${prefix}  and  ${exec_prefix}  are  installation-dependent  and
269       should  be  interpreted as for GNU software; they may be the same.  The
270       default for both is /usr/local.
271
272       ${exec_prefix}/bin/python
273              Recommended location of the interpreter.
274
275       ${prefix}/lib/python<version>
276       ${exec_prefix}/lib/python<version>
277              Recommended locations of the directories containing the standard
278              modules.
279
280       ${prefix}/include/python<version>
281       ${exec_prefix}/include/python<version>
282              Recommended  locations of the directories containing the include
283              files needed for developing Python extensions and embedding  the
284              interpreter.
285

ENVIRONMENT VARIABLES

287       PYTHONHOME
288              Change  the  location  of the standard Python libraries.  By de‐
289              fault, the libraries are searched  in  ${prefix}/lib/python<ver‐
290              sion>  and  ${exec_prefix}/lib/python<version>,  where ${prefix}
291              and ${exec_prefix} are installation-dependent directories,  both
292              defaulting  to  /usr/local.  When $PYTHONHOME is set to a single
293              directory, its value replaces both ${prefix} and ${exec_prefix}.
294              To specify different values for these, set $PYTHONHOME to ${pre‐
295              fix}:${exec_prefix}.
296
297       PYTHONPATH
298              Augments the default search path for module files.   The  format
299              is  the  same  as the shell's $PATH: one or more directory path‐
300              names  separated  by  colons.   Non-existent   directories   are
301              silently  ignored.   The default search path is installation de‐
302              pendent, but generally begins with ${prefix}/lib/python<version>
303              (see  PYTHONHOME  above).  The default search path is always ap‐
304              pended to $PYTHONPATH.  If a script argument is given,  the  di‐
305              rectory  containing  the script is inserted in the path in front
306              of $PYTHONPATH.  The search path can be manipulated from  within
307              a Python program as the variable sys.path.
308
309       PYTHONPLATLIBDIR
310              Override sys.platlibdir.
311
312       PYTHONSTARTUP
313              If  this  is the name of a readable file, the Python commands in
314              that file are executed before the first prompt is  displayed  in
315              interactive  mode.   The file is executed in the same name space
316              where interactive commands are executed so that objects  defined
317              or  imported  in it can be used without qualification in the in‐
318              teractive session.  You can also change the prompts sys.ps1  and
319              sys.ps2 in this file.
320
321       PYTHONOPTIMIZE
322              If  this is set to a non-empty string it is equivalent to speci‐
323              fying the -O option. If set to an integer, it is  equivalent  to
324              specifying -O multiple times.
325
326       PYTHONDEBUG
327              If  this is set to a non-empty string it is equivalent to speci‐
328              fying the -d option. If set to an integer, it is  equivalent  to
329              specifying -d multiple times.
330
331       PYTHONDONTWRITEBYTECODE
332              If  this is set to a non-empty string it is equivalent to speci‐
333              fying the -B option (don't try to write .pyc files).
334
335       PYTHONINSPECT
336              If this is set to a non-empty string it is equivalent to  speci‐
337              fying the -i option.
338
339       PYTHONIOENCODING
340              If  this is set before running the interpreter, it overrides the
341              encoding used for stdin/stdout/stderr, in the  syntax  encoding‐
342              name:errorhandler  The errorhandler part is optional and has the
343              same meaning as in str.encode. For stderr, the errorhandler
344               part is ignored; the handler will always be ´backslashreplace´.
345
346       PYTHONNOUSERSITE
347              If this is set to a non-empty string it is equivalent to  speci‐
348              fying  the  -s  option  (Don't  add  the  user site directory to
349              sys.path).
350
351       PYTHONUNBUFFERED
352              If this is set to a non-empty string it is equivalent to  speci‐
353              fying the -u option.
354
355       PYTHONVERBOSE
356              If  this is set to a non-empty string it is equivalent to speci‐
357              fying the -v option. If set to an integer, it is  equivalent  to
358              specifying -v multiple times.
359
360       PYTHONWARNINGS
361              If  this  is set to a comma-separated string it is equivalent to
362              specifying the -W option for each separate value.
363
364       PYTHONHASHSEED
365              If this variable is set to "random", a random value is  used  to
366              seed the hashes of str and bytes objects.
367
368              If  PYTHONHASHSEED  is  set to an integer value, it is used as a
369              fixed seed for generating the hash() of the types covered by the
370              hash randomization.  Its purpose is to allow repeatable hashing,
371              such as for selftests for the interpreter itself, or to allow  a
372              cluster of python processes to share hash values.
373
374              The   integer   must   be   a   decimal   number  in  the  range
375              [0,4294967295].  Specifying the value 0 will disable  hash  ran‐
376              domization.
377
378       PYTHONINTMAXSTRDIGITS
379              Limit the maximum digit characters in an int value when convert‐
380              ing from a string and when converting an int back to a  str.   A
381              value  of 0 disables the limit.  Conversions to or from bases 2,
382              4, 8, 16, and 32 are never limited.
383
384       PYTHONMALLOC
385              Set the Python memory allocators and/or install debug hooks. The
386              available memory allocators are malloc and pymalloc.  The avail‐
387              able debug hooks are debug, malloc_debug, and pymalloc_debug.
388
389              When Python is compiled in debug mode,  the  default  is  pymal‐
390              loc_debug and the debug hooks are automatically used. Otherwise,
391              the default is pymalloc.
392
393       PYTHONMALLOCSTATS
394              If set to a non-empty string, Python will  print  statistics  of
395              the  pymalloc  memory allocator every time a new pymalloc object
396              arena is created, and on shutdown.
397
398              This variable is ignored if the $PYTHONMALLOC environment  vari‐
399              able  is used to force the malloc(3) allocator of the C library,
400              or if Python is configured without pymalloc support.
401
402       PYTHONASYNCIODEBUG
403              If this environment variable is set to a non-empty  string,  en‐
404              able the debug mode of the asyncio module.
405
406       PYTHONTRACEMALLOC
407              If this environment variable is set to a non-empty string, start
408              tracing Python memory allocations using the tracemalloc module.
409
410              The value of the variable is the maximum number of frames stored
411              in  a  traceback  of  a  trace. For example, PYTHONTRACEMALLOC=1
412              stores only the most recent frame.
413
414       PYTHONFAULTHANDLER
415              If this environment variable  is  set  to  a  non-empty  string,
416              faulthandler.enable()  is  called  at startup: install a handler
417              for SIGSEGV, SIGFPE, SIGABRT, SIGBUS and SIGILL signals to  dump
418              the Python traceback.
419
420              This is equivalent to the -X faulthandler option.
421
422       PYTHONEXECUTABLE
423              If  this environment variable is set, sys.argv[0] will be set to
424              its value instead of the value got through the C  runtime.  Only
425              works on Mac OS X.
426
427       PYTHONUSERBASE
428              Defines  the  user  base directory, which is used to compute the
429              path of the user site-packages directory and Distutils installa‐
430              tion paths for python setup.py install --user.
431
432       PYTHONPROFILEIMPORTTIME
433              If  this  environment  variable  is  set  to a non-empty string,
434              Python will show how long each import  takes.  This  is  exactly
435              equivalent to setting -X importtime on the command line.
436
437       PYTHONBREAKPOINT
438              If  this  environment  variable is set to 0, it disables the de‐
439              fault debugger. It can be set to the callable of  your  debugger
440              of choice.
441
442   Debug-mode variables
443       Setting  these variables only has an effect in a debug build of Python,
444       that is, if Python was configured with the --with-pydebug build option.
445
446       PYTHONTHREADDEBUG
447              If this environment variable is set, Python will print threading
448              debug  info.   The feature is deprecated in Python 3.10 and will
449              be removed in Python 3.12.
450
451       PYTHONDUMPREFS
452              If this environment variable is set, Python  will  dump  objects
453              and  reference counts still alive after shutting down the inter‐
454              preter.
455

AUTHOR

457       The Python Software Foundation: https://www.python.org/psf/
458

INTERNET RESOURCES

460       Main website:  https://www.python.org/
461       Documentation:  https://docs.python.org/
462       Developer resources:  https://devguide.python.org/
463       Downloads:  https://www.python.org/downloads/
464       Module repository:  https://pypi.org/
465       Newsgroups:  comp.lang.python, comp.lang.python.announce
466

LICENSING

468       Python is distributed under an Open Source license.  See the file  "LI‐
469       CENSE"  in  the  Python  source distribution for information on terms &
470       conditions for accessing and otherwise using  Python  and  for  a  DIS‐
471       CLAIMER OF ALL WARRANTIES.
472
473
474
475                                                                     PYTHON(1)
Impressum