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() C function
204                         * Enable the faulthandler module to dump  the  Python
205              traceback on a crash
206                         * Enable asyncio debug mode
207                         * Set the dev_mode attribute of sys.flags to True
208                         * io.IOBase destructor logs close() exceptions
209
210                  -X  utf8: enable UTF-8 mode for operating system interfaces,
211              overriding the default
212                      locale-aware mode. -X utf8=0 explicitly  disables  UTF-8
213              mode (even when it would
214                      otherwise  activate  automatically).  See PYTHONUTF8 for
215              more details
216
217                  -X pycache_prefix=PATH: enable writing .pyc files to a  par‐
218              allel tree rooted at the
219                       given directory instead of to the code tree.
220
221       -x     Skip  the  first line of the source.  This is intended for a DOS
222              specific hack only.  Warning: the line numbers in error messages
223              will be off by one!
224

INTERPRETER INTERFACE

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

FILES AND DIRECTORIES

255       These are subject to difference depending on local installation conven‐
256       tions; ${prefix}  and  ${exec_prefix}  are  installation-dependent  and
257       should  be  interpreted as for GNU software; they may be the same.  The
258       default for both is /usr/local.
259
260       ${exec_prefix}/bin/python
261              Recommended location of the interpreter.
262
263       ${prefix}/lib/python<version>
264       ${exec_prefix}/lib/python<version>
265              Recommended locations of the directories containing the standard
266              modules.
267
268       ${prefix}/include/python<version>
269       ${exec_prefix}/include/python<version>
270              Recommended  locations of the directories containing the include
271              files needed for developing Python extensions and embedding  the
272              interpreter.
273

ENVIRONMENT VARIABLES

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

AUTHOR

439       The Python Software Foundation: https://www.python.org/psf/
440

INTERNET RESOURCES

442       Main website:  https://www.python.org/
443       Documentation:  https://docs.python.org/
444       Developer resources:  https://devguide.python.org/
445       Downloads:  https://www.python.org/downloads/
446       Module repository:  https://pypi.org/
447       Newsgroups:  comp.lang.python, comp.lang.python.announce
448

LICENSING

450       Python  is distributed under an Open Source license.  See the file "LI‐
451       CENSE" in the Python source distribution for  information  on  terms  &
452       conditions  for  accessing  and  otherwise  using Python and for a DIS‐
453       CLAIMER OF ALL WARRANTIES.
454
455
456
457                                                                     PYTHON(1)
Impressum