Benjamin Peterson | b9869df | 2016-03-21 22:31:02 -0700 | [diff] [blame] | 1 | .TH PYTHON "1" |
Andrew M. Kuchling | 3afe4f3 | 2004-10-07 12:30:54 +0000 | [diff] [blame] | 2 | |
Benjamin Peterson | 5f28b7b | 2009-03-26 21:49:58 +0000 | [diff] [blame] | 3 | .\" To view this file while editing, run it through groff: |
| 4 | .\" groff -Tascii -man python.man | less |
Andrew M. Kuchling | 3afe4f3 | 2004-10-07 12:30:54 +0000 | [diff] [blame] | 5 | |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 6 | .SH NAME |
| 7 | python \- an interpreted, interactive, object-oriented programming language |
| 8 | .SH SYNOPSIS |
| 9 | .B python |
| 10 | [ |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 11 | .B \-B |
| 12 | ] |
| 13 | [ |
Senthil Kumaran | ce3dd0b | 2013-06-19 22:19:46 -0500 | [diff] [blame] | 14 | .B \-b |
| 15 | ] |
| 16 | [ |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 17 | .B \-d |
| 18 | ] |
| 19 | [ |
Guido van Rossum | b674baf | 2001-09-05 18:55:34 +0000 | [diff] [blame] | 20 | .B \-E |
| 21 | ] |
| 22 | [ |
| 23 | .B \-h |
| 24 | ] |
| 25 | [ |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 26 | .B \-i |
| 27 | ] |
| 28 | [ |
Christian Heimes | ad73a9c | 2013-08-10 16:36:18 +0200 | [diff] [blame] | 29 | .B \-I |
Andrew M. Kuchling | 166e625 | 2004-10-07 12:04:50 +0000 | [diff] [blame] | 30 | ] |
Guido van Rossum | b674baf | 2001-09-05 18:55:34 +0000 | [diff] [blame] | 31 | .br |
| 32 | [ |
Christian Heimes | ad73a9c | 2013-08-10 16:36:18 +0200 | [diff] [blame] | 33 | .B \-m |
| 34 | .I module-name |
| 35 | ] |
| 36 | [ |
Senthil Kumaran | ce3dd0b | 2013-06-19 22:19:46 -0500 | [diff] [blame] | 37 | .B \-q |
| 38 | ] |
| 39 | [ |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 40 | .B \-O |
| 41 | ] |
| 42 | [ |
R David Murray | 9c4f09d | 2011-05-01 11:13:56 -0400 | [diff] [blame] | 43 | .B \-OO |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 44 | ] |
| 45 | [ |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 46 | .B \-s |
| 47 | ] |
| 48 | [ |
Guido van Rossum | b674baf | 2001-09-05 18:55:34 +0000 | [diff] [blame] | 49 | .B \-S |
Neil Schemenauer | 7d4bb9f | 2001-07-23 16:30:27 +0000 | [diff] [blame] | 50 | ] |
| 51 | [ |
Guido van Rossum | ef5bca3 | 1994-05-03 14:15:32 +0000 | [diff] [blame] | 52 | .B \-u |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 53 | ] |
Guido van Rossum | b674baf | 2001-09-05 18:55:34 +0000 | [diff] [blame] | 54 | .br |
| 55 | [ |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 56 | .B \-v |
| 57 | ] |
Guido van Rossum | 07c44c7 | 1998-04-10 19:46:00 +0000 | [diff] [blame] | 58 | [ |
Barry Warsaw | 6456937 | 2000-09-15 18:39:09 +0000 | [diff] [blame] | 59 | .B \-V |
| 60 | ] |
Guido van Rossum | 1378c32 | 2000-12-19 03:21:54 +0000 | [diff] [blame] | 61 | [ |
| 62 | .B \-W |
| 63 | .I argument |
| 64 | ] |
Guido van Rossum | b674baf | 2001-09-05 18:55:34 +0000 | [diff] [blame] | 65 | [ |
| 66 | .B \-x |
| 67 | ] |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 68 | [ |
Senthil Kumaran | ce3dd0b | 2013-06-19 22:19:46 -0500 | [diff] [blame] | 69 | [ |
| 70 | .B \-X |
| 71 | .I option |
| 72 | ] |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 73 | .B \-? |
| 74 | ] |
Guido van Rossum | 4cf4de5 | 1997-09-08 04:06:15 +0000 | [diff] [blame] | 75 | .br |
| 76 | [ |
Benjamin Peterson | 42aa93b | 2017-12-09 10:26:52 -0800 | [diff] [blame] | 77 | .B \--check-hash-based-pycs |
Miro Hrončok | 16323cb | 2019-02-25 01:50:29 +0100 | [diff] [blame] | 78 | .I default |
| 79 | | |
| 80 | .I always |
| 81 | | |
| 82 | .I never |
Benjamin Peterson | 42aa93b | 2017-12-09 10:26:52 -0800 | [diff] [blame] | 83 | ] |
| 84 | .br |
| 85 | [ |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 86 | .B \-c |
| 87 | .I command |
| 88 | | |
| 89 | .I script |
| 90 | | |
| 91 | \- |
| 92 | ] |
| 93 | [ |
| 94 | .I arguments |
| 95 | ] |
| 96 | .SH DESCRIPTION |
| 97 | Python is an interpreted, interactive, object-oriented programming |
| 98 | language that combines remarkable power with very clear syntax. |
Benjamin Peterson | b0335ee | 2015-04-29 18:00:44 -0400 | [diff] [blame] | 99 | For an introduction to programming in Python, see the Python Tutorial. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 100 | The Python Library Reference documents built-in and standard types, |
| 101 | constants, functions and modules. |
| 102 | Finally, the Python Reference Manual describes the syntax and |
| 103 | semantics of the core language in (perhaps too) much detail. |
Guido van Rossum | f4a090d | 2000-09-01 20:36:34 +0000 | [diff] [blame] | 104 | (These documents may be located via the |
| 105 | .B "INTERNET RESOURCES" |
Fred Drake | 4c9be9d | 1999-08-20 13:10:20 +0000 | [diff] [blame] | 106 | below; they may be installed on your system as well.) |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 107 | .PP |
| 108 | Python's basic power can be extended with your own modules written in |
| 109 | C or C++. |
Guido van Rossum | 74faed2 | 1996-07-30 19:27:05 +0000 | [diff] [blame] | 110 | On most systems such modules may be dynamically loaded. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 111 | Python is also adaptable as an extension language for existing |
| 112 | applications. |
| 113 | See the internal documentation for hints. |
Andrew M. Kuchling | 88717f4 | 2001-04-05 14:50:40 +0000 | [diff] [blame] | 114 | .PP |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 115 | Documentation for installed Python modules and packages can be |
| 116 | viewed by running the |
Andrew M. Kuchling | 88717f4 | 2001-04-05 14:50:40 +0000 | [diff] [blame] | 117 | .B pydoc |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 118 | program. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 119 | .SH COMMAND LINE OPTIONS |
| 120 | .TP |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 121 | .B \-B |
| 122 | Don't write |
Brett Cannon | 10a7dbd | 2016-10-21 12:15:14 -0700 | [diff] [blame] | 123 | .I .pyc |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 124 | files on import. See also PYTHONDONTWRITEBYTECODE. |
| 125 | .TP |
Senthil Kumaran | ce3dd0b | 2013-06-19 22:19:46 -0500 | [diff] [blame] | 126 | .B \-b |
| 127 | Issue warnings about str(bytes_instance), str(bytearray_instance) |
| 128 | and comparing bytes/bytearray with str. (-bb: issue errors) |
| 129 | .TP |
Guido van Rossum | b674baf | 2001-09-05 18:55:34 +0000 | [diff] [blame] | 130 | .BI "\-c " command |
| 131 | Specify the command to execute (see next section). |
| 132 | This terminates the option list (following options are passed as |
| 133 | arguments to the command). |
| 134 | .TP |
Benjamin Peterson | 42aa93b | 2017-12-09 10:26:52 -0800 | [diff] [blame] | 135 | .BI "\-\-check-hash-based-pycs " mode |
| 136 | Configure how Python evaluates the up-to-dateness of hash-based .pyc files. |
| 137 | .TP |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 138 | .B \-d |
Victor Stinner | 84c4b19 | 2017-11-24 22:30:27 +0100 | [diff] [blame] | 139 | Turn on parser debugging output (for expert only, depending on |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 140 | compilation options). |
Guido van Rossum | 9f65ae0 | 1994-02-23 09:10:27 +0000 | [diff] [blame] | 141 | .TP |
Guido van Rossum | b674baf | 2001-09-05 18:55:34 +0000 | [diff] [blame] | 142 | .B \-E |
| 143 | Ignore environment variables like PYTHONPATH and PYTHONHOME that modify |
| 144 | the behavior of the interpreter. |
| 145 | .TP |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 146 | .B \-h ", " \-? ", "\-\-help |
Guido van Rossum | b674baf | 2001-09-05 18:55:34 +0000 | [diff] [blame] | 147 | Prints the usage for the interpreter executable and exits. |
| 148 | .TP |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 149 | .B \-i |
| 150 | When a script is passed as first argument or the \fB\-c\fP option is |
| 151 | used, enter interactive mode after executing the script or the |
Guido van Rossum | 9f65ae0 | 1994-02-23 09:10:27 +0000 | [diff] [blame] | 152 | command. It does not read the $PYTHONSTARTUP file. This can be |
| 153 | useful to inspect global variables or a stack trace when a script |
| 154 | raises an exception. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 155 | .TP |
Christian Heimes | ad73a9c | 2013-08-10 16:36:18 +0200 | [diff] [blame] | 156 | .B \-I |
Ned Deily | 64298ae | 2015-04-29 14:51:43 -0700 | [diff] [blame] | 157 | Run Python in isolated mode. This also implies \fB\-E\fP and \fB\-s\fP. In |
Serhiy Storchaka | 225821c | 2015-12-18 13:05:04 +0200 | [diff] [blame] | 158 | isolated mode sys.path contains neither the script's directory nor the user's |
Christian Heimes | ad73a9c | 2013-08-10 16:36:18 +0200 | [diff] [blame] | 159 | site-packages directory. All PYTHON* environment variables are ignored, too. |
| 160 | Further restrictions may be imposed to prevent the user from injecting |
| 161 | malicious code. |
| 162 | .TP |
Andrew M. Kuchling | 166e625 | 2004-10-07 12:04:50 +0000 | [diff] [blame] | 163 | .BI "\-m " module-name |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 164 | Searches |
| 165 | .I sys.path |
| 166 | for the named module and runs the corresponding |
| 167 | .I .py |
Andrew M. Kuchling | 166e625 | 2004-10-07 12:04:50 +0000 | [diff] [blame] | 168 | file as a script. |
| 169 | .TP |
Guido van Rossum | 4cf4de5 | 1997-09-08 04:06:15 +0000 | [diff] [blame] | 170 | .B \-O |
Cheryl Sabella | 186b606 | 2018-02-24 22:04:40 -0500 | [diff] [blame] | 171 | Remove assert statements and any code conditional on the value of |
| 172 | __debug__; augment the filename for compiled (bytecode) files by |
| 173 | adding .opt-1 before the .pyc extension. |
Guido van Rossum | 4cf4de5 | 1997-09-08 04:06:15 +0000 | [diff] [blame] | 174 | .TP |
R David Murray | 9c4f09d | 2011-05-01 11:13:56 -0400 | [diff] [blame] | 175 | .B \-OO |
Cheryl Sabella | 186b606 | 2018-02-24 22:04:40 -0500 | [diff] [blame] | 176 | Do \fB-O\fP and also discard docstrings; change the filename for |
| 177 | compiled (bytecode) files by adding .opt-2 before the .pyc extension. |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 178 | .TP |
Georg Brandl | 9d87119 | 2010-12-04 10:47:18 +0000 | [diff] [blame] | 179 | .B \-q |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 180 | Do not print the version and copyright messages. These messages are |
Georg Brandl | 9d87119 | 2010-12-04 10:47:18 +0000 | [diff] [blame] | 181 | also suppressed in non-interactive mode. |
| 182 | .TP |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 183 | .B \-s |
| 184 | Don't add user site directory to sys.path. |
| 185 | .TP |
Guido van Rossum | 4cf4de5 | 1997-09-08 04:06:15 +0000 | [diff] [blame] | 186 | .B \-S |
| 187 | Disable the import of the module |
| 188 | .I site |
| 189 | and the site-dependent manipulations of |
| 190 | .I sys.path |
Éric Araujo | c09fca6 | 2011-03-23 02:06:24 +0100 | [diff] [blame] | 191 | that it entails. Also disable these manipulations if |
| 192 | .I site |
| 193 | is explicitly imported later. |
Guido van Rossum | 4cf4de5 | 1997-09-08 04:06:15 +0000 | [diff] [blame] | 194 | .TP |
Guido van Rossum | ef5bca3 | 1994-05-03 14:15:32 +0000 | [diff] [blame] | 195 | .B \-u |
Berker Peksag | 7f58097 | 2017-10-13 15:16:31 +0300 | [diff] [blame] | 196 | Force the stdout and stderr streams to be unbuffered. |
| 197 | This option has no effect on the stdin stream. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 198 | .TP |
| 199 | .B \-v |
| 200 | Print a message each time a module is initialized, showing the place |
Fred Drake | 4c9be9d | 1999-08-20 13:10:20 +0000 | [diff] [blame] | 201 | (filename or built-in module) from which it is loaded. When given |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 202 | twice, print a message for each file that is checked for when |
Fred Drake | 4c9be9d | 1999-08-20 13:10:20 +0000 | [diff] [blame] | 203 | searching for a module. Also provides information on module cleanup |
| 204 | at exit. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 205 | .TP |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 206 | .B \-V ", " \-\-version |
INADA Naoki | 0e175a6 | 2016-11-21 20:57:14 +0900 | [diff] [blame] | 207 | Prints the Python version number of the executable and exits. When given |
| 208 | twice, print more information about the build. |
Barry Warsaw | 6456937 | 2000-09-15 18:39:09 +0000 | [diff] [blame] | 209 | .TP |
Guido van Rossum | 1378c32 | 2000-12-19 03:21:54 +0000 | [diff] [blame] | 210 | .BI "\-W " argument |
| 211 | Warning control. Python sometimes prints warning message to |
| 212 | .IR sys.stderr . |
| 213 | A typical warning message has the following form: |
| 214 | .IB file ":" line ": " category ": " message. |
| 215 | By default, each warning is printed once for each source line where it |
| 216 | occurs. This option controls how often warnings are printed. |
| 217 | Multiple |
| 218 | .B \-W |
| 219 | options may be given; when a warning matches more than one |
| 220 | option, the action for the last matching option is performed. |
| 221 | Invalid |
| 222 | .B \-W |
| 223 | options are ignored (a warning message is printed about invalid |
| 224 | options when the first warning is issued). Warnings can also be |
| 225 | controlled from within a Python program using the |
| 226 | .I warnings |
| 227 | module. |
| 228 | |
| 229 | The simplest form of |
| 230 | .I argument |
| 231 | is one of the following |
| 232 | .I action |
| 233 | strings (or a unique abbreviation): |
| 234 | .B ignore |
| 235 | to ignore all warnings; |
| 236 | .B default |
| 237 | to explicitly request the default behavior (printing each warning once |
| 238 | per source line); |
| 239 | .B all |
| 240 | to print a warning each time it occurs (this may generate many |
| 241 | messages if a warning is triggered repeatedly for the same source |
Fred Drake | bd2e3b0 | 2001-07-26 21:25:58 +0000 | [diff] [blame] | 242 | line, such as inside a loop); |
Guido van Rossum | 1378c32 | 2000-12-19 03:21:54 +0000 | [diff] [blame] | 243 | .B module |
Georg Brandl | eeb575f | 2009-06-24 06:42:05 +0000 | [diff] [blame] | 244 | to print each warning only the first time it occurs in each |
Guido van Rossum | 1378c32 | 2000-12-19 03:21:54 +0000 | [diff] [blame] | 245 | module; |
| 246 | .B once |
| 247 | to print each warning only the first time it occurs in the program; or |
| 248 | .B error |
| 249 | to raise an exception instead of printing a warning message. |
| 250 | |
| 251 | The full form of |
| 252 | .I argument |
| 253 | is |
| 254 | .IB action : message : category : module : line. |
| 255 | Here, |
| 256 | .I action |
| 257 | is as explained above but only applies to messages that match the |
| 258 | remaining fields. Empty fields match all values; trailing empty |
| 259 | fields may be omitted. The |
| 260 | .I message |
| 261 | field matches the start of the warning message printed; this match is |
| 262 | case-insensitive. The |
| 263 | .I category |
| 264 | field matches the warning category. This must be a class name; the |
| 265 | match test whether the actual warning category of the message is a |
| 266 | subclass of the specified warning category. The full class name must |
| 267 | be given. The |
| 268 | .I module |
| 269 | field matches the (fully-qualified) module name; this match is |
| 270 | case-sensitive. The |
| 271 | .I line |
| 272 | field matches the line number, where zero matches all line numbers and |
| 273 | is thus equivalent to an omitted line number. |
| 274 | .TP |
Senthil Kumaran | ce3dd0b | 2013-06-19 22:19:46 -0500 | [diff] [blame] | 275 | .BI "\-X " option |
Pablo Galindo | 41f0ef6 | 2020-01-23 01:03:04 +0000 | [diff] [blame] | 276 | Set implementation specific option. The following options are available: |
| 277 | |
| 278 | -X faulthandler: enable faulthandler |
| 279 | |
| 280 | -X showrefcount: output the total reference count and number of used |
| 281 | memory blocks when the program finishes or after each statement in the |
| 282 | interactive interpreter. This only works on debug builds |
| 283 | |
| 284 | -X tracemalloc: start tracing Python memory allocations using the |
| 285 | tracemalloc module. By default, only the most recent frame is stored in a |
| 286 | traceback of a trace. Use -X tracemalloc=NFRAME to start tracing with a |
| 287 | traceback limit of NFRAME frames |
| 288 | |
Pablo Galindo | 41f0ef6 | 2020-01-23 01:03:04 +0000 | [diff] [blame] | 289 | -X importtime: show how long each import takes. It shows module name, |
| 290 | cumulative time (including nested imports) and self time (excluding |
| 291 | nested imports). Note that its output may be broken in multi-threaded |
| 292 | application. Typical usage is python3 -X importtime -c 'import asyncio' |
| 293 | |
Serhiy Storchaka | 58de1dd | 2020-09-09 03:28:02 +0300 | [diff] [blame] | 294 | -X dev: enable CPython's "development mode", introducing additional runtime |
Pablo Galindo | 41f0ef6 | 2020-01-23 01:03:04 +0000 | [diff] [blame] | 295 | checks which are too expensive to be enabled by default. It will not be |
| 296 | more verbose than the default if the code is correct: new warnings are |
| 297 | only emitted when an issue is detected. Effect of the developer mode: |
| 298 | * Add default warning filter, as -W default |
| 299 | * Install debug hooks on memory allocators: see the PyMem_SetupDebugHooks() C function |
| 300 | * Enable the faulthandler module to dump the Python traceback on a crash |
| 301 | * Enable asyncio debug mode |
| 302 | * Set the dev_mode attribute of sys.flags to True |
| 303 | * io.IOBase destructor logs close() exceptions |
| 304 | |
| 305 | -X utf8: enable UTF-8 mode for operating system interfaces, overriding the default |
| 306 | locale-aware mode. -X utf8=0 explicitly disables UTF-8 mode (even when it would |
| 307 | otherwise activate automatically). See PYTHONUTF8 for more details |
| 308 | |
| 309 | -X pycache_prefix=PATH: enable writing .pyc files to a parallel tree rooted at the |
| 310 | given directory instead of to the code tree. |
Senthil Kumaran | ce3dd0b | 2013-06-19 22:19:46 -0500 | [diff] [blame] | 311 | .TP |
Guido van Rossum | b674baf | 2001-09-05 18:55:34 +0000 | [diff] [blame] | 312 | .B \-x |
| 313 | Skip the first line of the source. This is intended for a DOS |
| 314 | specific hack only. Warning: the line numbers in error messages will |
| 315 | be off by one! |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 316 | .SH INTERPRETER INTERFACE |
| 317 | The interpreter interface resembles that of the UNIX shell: when |
| 318 | called with standard input connected to a tty device, it prompts for |
| 319 | commands and executes them until an EOF is read; when called with a |
| 320 | file name argument or with a file as standard input, it reads and |
| 321 | executes a |
| 322 | .I script |
| 323 | from that file; |
| 324 | when called with |
| 325 | .B \-c |
doko@ubuntu.com | d8623e8 | 2012-06-20 13:16:31 +0200 | [diff] [blame] | 326 | .IR command , |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 327 | it executes the Python statement(s) given as |
doko@ubuntu.com | d8623e8 | 2012-06-20 13:16:31 +0200 | [diff] [blame] | 328 | .IR command . |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 329 | Here |
| 330 | .I command |
| 331 | may contain multiple statements separated by newlines. |
| 332 | Leading whitespace is significant in Python statements! |
Matthias Klose | 31a58df | 2005-03-20 14:16:03 +0000 | [diff] [blame] | 333 | In non-interactive mode, the entire input is parsed before it is |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 334 | executed. |
| 335 | .PP |
| 336 | If available, the script name and additional arguments thereafter are |
| 337 | passed to the script in the Python variable |
doko@ubuntu.com | d8623e8 | 2012-06-20 13:16:31 +0200 | [diff] [blame] | 338 | .IR sys.argv , |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 339 | which is a list of strings (you must first |
| 340 | .I import sys |
| 341 | to be able to access it). |
| 342 | If no script name is given, |
Guido van Rossum | f4a090d | 2000-09-01 20:36:34 +0000 | [diff] [blame] | 343 | .I sys.argv[0] |
| 344 | is an empty string; if |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 345 | .B \-c |
| 346 | is used, |
| 347 | .I sys.argv[0] |
| 348 | contains the string |
| 349 | .I '-c'. |
Guido van Rossum | 74faed2 | 1996-07-30 19:27:05 +0000 | [diff] [blame] | 350 | Note that options interpreted by the Python interpreter itself |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 351 | are not placed in |
doko@ubuntu.com | d8623e8 | 2012-06-20 13:16:31 +0200 | [diff] [blame] | 352 | .IR sys.argv . |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 353 | .PP |
| 354 | In interactive mode, the primary prompt is `>>>'; the second prompt |
| 355 | (which appears when a command is not complete) is `...'. |
| 356 | The prompts can be changed by assignment to |
| 357 | .I sys.ps1 |
| 358 | or |
doko@ubuntu.com | d8623e8 | 2012-06-20 13:16:31 +0200 | [diff] [blame] | 359 | .IR sys.ps2 . |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 360 | The interpreter quits when it reads an EOF at a prompt. |
| 361 | When an unhandled exception occurs, a stack trace is printed and |
| 362 | control returns to the primary prompt; in non-interactive mode, the |
| 363 | interpreter exits after printing the stack trace. |
| 364 | The interrupt signal raises the |
| 365 | .I Keyboard\%Interrupt |
| 366 | exception; other UNIX signals are not caught (except that SIGPIPE is |
| 367 | sometimes ignored, in favor of the |
| 368 | .I IOError |
| 369 | exception). Error messages are written to stderr. |
| 370 | .SH FILES AND DIRECTORIES |
| 371 | These are subject to difference depending on local installation |
Fred Drake | 4c9be9d | 1999-08-20 13:10:20 +0000 | [diff] [blame] | 372 | conventions; ${prefix} and ${exec_prefix} are installation-dependent |
| 373 | and should be interpreted as for GNU software; they may be the same. |
| 374 | The default for both is \fI/usr/local\fP. |
| 375 | .IP \fI${exec_prefix}/bin/python\fP |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 376 | Recommended location of the interpreter. |
Fred Drake | 4c9be9d | 1999-08-20 13:10:20 +0000 | [diff] [blame] | 377 | .PP |
| 378 | .I ${prefix}/lib/python<version> |
| 379 | .br |
| 380 | .I ${exec_prefix}/lib/python<version> |
| 381 | .RS |
| 382 | Recommended locations of the directories containing the standard |
| 383 | modules. |
| 384 | .RE |
| 385 | .PP |
| 386 | .I ${prefix}/include/python<version> |
| 387 | .br |
| 388 | .I ${exec_prefix}/include/python<version> |
| 389 | .RS |
| 390 | Recommended locations of the directories containing the include files |
| 391 | needed for developing Python extensions and embedding the |
| 392 | interpreter. |
| 393 | .RE |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 394 | .SH ENVIRONMENT VARIABLES |
Guido van Rossum | 4cf4de5 | 1997-09-08 04:06:15 +0000 | [diff] [blame] | 395 | .IP PYTHONHOME |
| 396 | Change the location of the standard Python libraries. By default, the |
Fred Drake | 4c9be9d | 1999-08-20 13:10:20 +0000 | [diff] [blame] | 397 | libraries are searched in ${prefix}/lib/python<version> and |
| 398 | ${exec_prefix}/lib/python<version>, where ${prefix} and ${exec_prefix} |
Guido van Rossum | 4cf4de5 | 1997-09-08 04:06:15 +0000 | [diff] [blame] | 399 | are installation-dependent directories, both defaulting to |
Fred Drake | 4c9be9d | 1999-08-20 13:10:20 +0000 | [diff] [blame] | 400 | \fI/usr/local\fP. When $PYTHONHOME is set to a single directory, its value |
| 401 | replaces both ${prefix} and ${exec_prefix}. To specify different values |
| 402 | for these, set $PYTHONHOME to ${prefix}:${exec_prefix}. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 403 | .IP PYTHONPATH |
| 404 | Augments the default search path for module files. |
| 405 | The format is the same as the shell's $PATH: one or more directory |
| 406 | pathnames separated by colons. |
Matthias Klose | 31a58df | 2005-03-20 14:16:03 +0000 | [diff] [blame] | 407 | Non-existent directories are silently ignored. |
Guido van Rossum | 4cf4de5 | 1997-09-08 04:06:15 +0000 | [diff] [blame] | 408 | The default search path is installation dependent, but generally |
Fred Drake | 4c9be9d | 1999-08-20 13:10:20 +0000 | [diff] [blame] | 409 | begins with ${prefix}/lib/python<version> (see PYTHONHOME above). |
Guido van Rossum | 4cf4de5 | 1997-09-08 04:06:15 +0000 | [diff] [blame] | 410 | The default search path is always appended to $PYTHONPATH. |
Guido van Rossum | 74faed2 | 1996-07-30 19:27:05 +0000 | [diff] [blame] | 411 | If a script argument is given, the directory containing the script is |
| 412 | inserted in the path in front of $PYTHONPATH. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 413 | The search path can be manipulated from within a Python program as the |
| 414 | variable |
doko@ubuntu.com | d8623e8 | 2012-06-20 13:16:31 +0200 | [diff] [blame] | 415 | .IR sys.path . |
Sandro Mani | 8f023a2 | 2020-06-08 17:28:11 +0200 | [diff] [blame] | 416 | .IP PYTHONPLATLIBDIR |
| 417 | Override sys.platlibdir. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 418 | .IP PYTHONSTARTUP |
| 419 | If this is the name of a readable file, the Python commands in that |
| 420 | file are executed before the first prompt is displayed in interactive |
| 421 | mode. |
| 422 | The file is executed in the same name space where interactive commands |
| 423 | are executed so that objects defined or imported in it can be used |
| 424 | without qualification in the interactive session. |
| 425 | You can also change the prompts |
| 426 | .I sys.ps1 |
| 427 | and |
| 428 | .I sys.ps2 |
| 429 | in this file. |
Guido van Rossum | 9abaf4d | 2001-10-12 22:17:56 +0000 | [diff] [blame] | 430 | .IP PYTHONOPTIMIZE |
| 431 | If this is set to a non-empty string it is equivalent to specifying |
| 432 | the \fB\-O\fP option. If set to an integer, it is equivalent to |
| 433 | specifying \fB\-O\fP multiple times. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 434 | .IP PYTHONDEBUG |
| 435 | If this is set to a non-empty string it is equivalent to specifying |
Guido van Rossum | 9abaf4d | 2001-10-12 22:17:56 +0000 | [diff] [blame] | 436 | the \fB\-d\fP option. If set to an integer, it is equivalent to |
| 437 | specifying \fB\-d\fP multiple times. |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 438 | .IP PYTHONDONTWRITEBYTECODE |
| 439 | If this is set to a non-empty string it is equivalent to specifying |
| 440 | the \fB\-B\fP option (don't try to write |
Brett Cannon | 10a7dbd | 2016-10-21 12:15:14 -0700 | [diff] [blame] | 441 | .I .pyc |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 442 | files). |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 443 | .IP PYTHONINSPECT |
| 444 | If this is set to a non-empty string it is equivalent to specifying |
| 445 | the \fB\-i\fP option. |
Benjamin Peterson | ee85a1d | 2010-10-13 22:20:15 +0000 | [diff] [blame] | 446 | .IP PYTHONIOENCODING |
| 447 | If this is set before running the interpreter, it overrides the encoding used |
| 448 | for stdin/stdout/stderr, in the syntax |
| 449 | .IB encodingname ":" errorhandler |
| 450 | The |
| 451 | .IB errorhandler |
| 452 | part is optional and has the same meaning as in str.encode. For stderr, the |
| 453 | .IB errorhandler |
| 454 | part is ignored; the handler will always be \'backslashreplace\'. |
Matthias Klose | c8b16f8 | 2010-01-31 16:14:37 +0000 | [diff] [blame] | 455 | .IP PYTHONNOUSERSITE |
Benjamin Peterson | ee85a1d | 2010-10-13 22:20:15 +0000 | [diff] [blame] | 456 | If this is set to a non-empty string it is equivalent to specifying the |
| 457 | \fB\-s\fP option (Don't add the user site directory to sys.path). |
Guido van Rossum | ef5bca3 | 1994-05-03 14:15:32 +0000 | [diff] [blame] | 458 | .IP PYTHONUNBUFFERED |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 459 | If this is set to a non-empty string it is equivalent to specifying |
Guido van Rossum | ef5bca3 | 1994-05-03 14:15:32 +0000 | [diff] [blame] | 460 | the \fB\-u\fP option. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 461 | .IP PYTHONVERBOSE |
| 462 | If this is set to a non-empty string it is equivalent to specifying |
Guido van Rossum | 9abaf4d | 2001-10-12 22:17:56 +0000 | [diff] [blame] | 463 | the \fB\-v\fP option. If set to an integer, it is equivalent to |
Brett Cannon | f299abd | 2015-04-13 14:21:02 -0400 | [diff] [blame] | 464 | specifying \fB\-v\fP multiple times. |
Philip Jenvey | 0805ca3 | 2010-04-07 04:04:10 +0000 | [diff] [blame] | 465 | .IP PYTHONWARNINGS |
| 466 | If this is set to a comma-separated string it is equivalent to |
| 467 | specifying the \fB\-W\fP option for each separate value. |
Georg Brandl | 2daf6ae | 2012-02-20 19:54:16 +0100 | [diff] [blame] | 468 | .IP PYTHONHASHSEED |
Benjamin Peterson | c9f54cf | 2012-02-21 16:08:05 -0500 | [diff] [blame] | 469 | If this variable is set to "random", a random value is used to seed the hashes |
Serhiy Storchaka | e9c90aa | 2019-08-24 12:49:27 +0300 | [diff] [blame] | 470 | of str and bytes objects. |
Georg Brandl | 2daf6ae | 2012-02-20 19:54:16 +0100 | [diff] [blame] | 471 | |
| 472 | If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for |
| 473 | generating the hash() of the types covered by the hash randomization. Its |
| 474 | purpose is to allow repeatable hashing, such as for selftests for the |
| 475 | interpreter itself, or to allow a cluster of python processes to share hash |
| 476 | values. |
| 477 | |
| 478 | The integer must be a decimal number in the range [0,4294967295]. Specifying |
Benjamin Peterson | c9f54cf | 2012-02-21 16:08:05 -0500 | [diff] [blame] | 479 | the value 0 will disable hash randomization. |
Berker Peksag | 9863de0 | 2018-07-09 22:17:54 +0300 | [diff] [blame] | 480 | .IP PYTHONMALLOC |
| 481 | Set the Python memory allocators and/or install debug hooks. The available |
| 482 | memory allocators are |
| 483 | .IR malloc |
| 484 | and |
| 485 | .IR pymalloc . |
| 486 | The available debug hooks are |
| 487 | .IR debug , |
| 488 | .IR malloc_debug , |
| 489 | and |
| 490 | .IR pymalloc_debug . |
| 491 | .IP |
| 492 | When Python is compiled in debug mode, the default is |
| 493 | .IR pymalloc_debug |
| 494 | and the debug hooks are automatically used. Otherwise, the default is |
| 495 | .IR pymalloc . |
| 496 | .IP PYTHONMALLOCSTATS |
| 497 | If set to a non-empty string, Python will print statistics of the pymalloc |
| 498 | memory allocator every time a new pymalloc object arena is created, and on |
| 499 | shutdown. |
| 500 | .IP |
| 501 | This variable is ignored if the |
| 502 | .RB $ PYTHONMALLOC |
| 503 | environment variable is used to force the |
| 504 | .BR malloc (3) |
| 505 | allocator of the C library, or if Python is configured without pymalloc support. |
| 506 | .IP PYTHONASYNCIODEBUG |
| 507 | If this environment variable is set to a non-empty string, enable the debug |
| 508 | mode of the asyncio module. |
| 509 | .IP PYTHONTRACEMALLOC |
| 510 | If this environment variable is set to a non-empty string, start tracing |
| 511 | Python memory allocations using the tracemalloc module. |
| 512 | .IP |
| 513 | The value of the variable is the maximum number of frames stored in a |
| 514 | traceback of a trace. For example, |
| 515 | .IB PYTHONTRACEMALLOC=1 |
| 516 | stores only the most recent frame. |
| 517 | .IP PYTHONFAULTHANDLER |
| 518 | If this environment variable is set to a non-empty string, |
| 519 | .IR faulthandler.enable() |
| 520 | is called at startup: install a handler for SIGSEGV, SIGFPE, SIGABRT, SIGBUS |
| 521 | and SIGILL signals to dump the Python traceback. |
| 522 | .IP |
| 523 | This is equivalent to the \fB-X faulthandler\fP option. |
| 524 | .IP PYTHONEXECUTABLE |
| 525 | If this environment variable is set, |
| 526 | .IB sys.argv[0] |
| 527 | will be set to its value instead of the value got through the C runtime. Only |
| 528 | works on Mac OS X. |
| 529 | .IP PYTHONUSERBASE |
| 530 | Defines the user base directory, which is used to compute the path of the user |
| 531 | .IR site-packages |
| 532 | directory and Distutils installation paths for |
| 533 | .IR "python setup\.py install \-\-user" . |
| 534 | .IP PYTHONPROFILEIMPORTTIME |
| 535 | If this environment variable is set to a non-empty string, Python will |
| 536 | show how long each import takes. This is exactly equivalent to setting |
| 537 | \fB\-X importtime\fP on the command line. |
Stéphane Wirtel | b7fd738 | 2018-07-29 12:27:16 +0200 | [diff] [blame] | 538 | .IP PYTHONBREAKPOINT |
| 539 | If this environment variable is set to 0, it disables the default debugger. It |
| 540 | can be set to the callable of your debugger of choice. |
Berker Peksag | 9863de0 | 2018-07-09 22:17:54 +0300 | [diff] [blame] | 541 | .SS Debug-mode variables |
| 542 | Setting these variables only has an effect in a debug build of Python, that is, |
| 543 | if Python was configured with the |
| 544 | \fB\--with-pydebug\fP build option. |
| 545 | .IP PYTHONTHREADDEBUG |
| 546 | If this environment variable is set, Python will print threading debug info. |
| 547 | .IP PYTHONDUMPREFS |
| 548 | If this environment variable is set, Python will dump objects and reference |
| 549 | counts still alive after shutting down the interpreter. |
Guido van Rossum | a7925f1 | 1994-01-26 10:20:16 +0000 | [diff] [blame] | 550 | .SH AUTHOR |
Benjamin Peterson | 37c4f78 | 2015-05-10 21:19:18 -0400 | [diff] [blame] | 551 | The Python Software Foundation: https://www.python.org/psf/ |
Guido van Rossum | 74faed2 | 1996-07-30 19:27:05 +0000 | [diff] [blame] | 552 | .SH INTERNET RESOURCES |
Benjamin Peterson | 755640b | 2015-04-30 17:37:11 -0400 | [diff] [blame] | 553 | Main website: https://www.python.org/ |
Guido van Rossum | 74faed2 | 1996-07-30 19:27:05 +0000 | [diff] [blame] | 554 | .br |
Benjamin Peterson | 755640b | 2015-04-30 17:37:11 -0400 | [diff] [blame] | 555 | Documentation: https://docs.python.org/ |
Guido van Rossum | f4a090d | 2000-09-01 20:36:34 +0000 | [diff] [blame] | 556 | .br |
Lisa Hewus Fresh | 384899d | 2017-08-30 09:37:43 -0700 | [diff] [blame] | 557 | Developer resources: https://devguide.python.org/ |
Guido van Rossum | f4a090d | 2000-09-01 20:36:34 +0000 | [diff] [blame] | 558 | .br |
Benjamin Peterson | 755640b | 2015-04-30 17:37:11 -0400 | [diff] [blame] | 559 | Downloads: https://www.python.org/downloads/ |
Guido van Rossum | f4a090d | 2000-09-01 20:36:34 +0000 | [diff] [blame] | 560 | .br |
Ned Deily | 9d6d06e | 2018-06-11 00:45:50 -0400 | [diff] [blame] | 561 | Module repository: https://pypi.org/ |
Guido van Rossum | 74faed2 | 1996-07-30 19:27:05 +0000 | [diff] [blame] | 562 | .br |
Fred Drake | bd2e3b0 | 2001-07-26 21:25:58 +0000 | [diff] [blame] | 563 | Newsgroups: comp.lang.python, comp.lang.python.announce |
Guido van Rossum | f4a090d | 2000-09-01 20:36:34 +0000 | [diff] [blame] | 564 | .SH LICENSING |
| 565 | Python is distributed under an Open Source license. See the file |
| 566 | "LICENSE" in the Python source distribution for information on terms & |
| 567 | conditions for accessing and otherwise using Python and for a |
| 568 | DISCLAIMER OF ALL WARRANTIES. |