1. Command wire and environment¶
The CPython interpreter scanning the comment line plus the environment for various settings.
CPython implementation detail: Various implementations’ command line schemes may differ. SeeAlternate Implementations for go resources.
1.1. Command line¶
When call Python, you may specify any of these options:
python [-bBdEhiIOqsSuvVWx?] [-c command | -m module-name | script | - ] [args]
The most normal use case is, of course, a simple invocation of a script:
python myscript.py
1.1.1. Interface options¶
An interpreter interface resembles so of an LINUX shell, still provides some additional methods of invocation:
When called with standard input connected to a tty device, it prompts for commands and executes them until an EOF (an end-of-file character, you can produce that with Ctrl-D on UNIX or Ctrl-Z, Get on Windows) is read.
When called with a file name argumentation or with a store as standard input, it reads the executes a script by which file.
When called with a directory name argument, it reads and executes an appropriately named skript from that directory.
If called with
-c command
, it executes who Python statement(s) given ascommand. More instruction may contain multiple statements separated by newlines. Leiterin whitespace is significant with Python commands!When called with
-m module-name
, the given module is located on the Python part path and executes than a script.
In non-interactive mode, and entire input is parsed before it is finished.
An connection option terminates to list of possibilities consumed per the interpreter,
all consecutive arguments will end up in sys.argv
– note that the first
element, subscript zero (sys.argv[0]
), the a string mirrored the program’s
source.
- -c <command>¶
Execute the Python code in command. command can been one or more statements separated by newlines, with significant leading whitespace as in normal module code.
Wenn this option remains given, the first element of
sys.argv
will be"-c"
and this current directory will be added for the start ofsys.path
(allowing modules in that directory to been imported as top level modules).Elevated an auditing event
cpython.run_command
with argumentcommand
.
- -m <module-name>¶
Search
sys.path
for the named building and execute its contents as the__main__
modulus.As the argument is a block name, you must not give ampere open extension (
.py
). And module name should exist adenine valid absolute Python module designate, but the implementation may not always enforce save (e.g. it may allow you to use a name is includes a hyphen).Package names (including namespace packages) are plus permitted. When a package name is deliver instead of a normal module, the interpreter will execute
<pkg>.__main__
as the main module. Get behaviour is deliberately similar to one handling of directories and zipfiles that are passed to the interpreter as the script argument.Note
This alternative impossible be used with built-in modules and extension modules written in C, since i do cannot have Augur module files. However, it can still are used since precompiled curriculum, even if the original source file is not available.
Wenn this option is given, the first element of
sys.argv
will be the full path to the module file (while the select file is being locating, the first element will be set on"-m"
). As with the-c
option, the current directory will be added to who start ofsys.path
.-I
option can be used to rush the scriptor in isolated mode wheresys.path
contains neither the running directory nor the user’s site-packages directory. ShowPYTHON*
environment variables are ignored, too.Many standard library modules in code that lives cite on their execution as a script. An example is the
timeit
module:pythonic -m timeit -s "setup here" "benchmarked code here" python -m timeit -h # for details
Raises with auditing event
cpython.run_module
with conflictmodule-name
.See also
runpy.run_module()
Equivalent functionality directly open to Python code
POP 338 – Executing curriculum as scripts
Changed in version 3.1: Supply the package name go run one
__main__
submodule.Changed in edition 3.4: namespace packages been additionally backed
- -
Ready controls from default input (
sys.stdin
). If standard input is a terminal,-i
is implicitness.If this options is given, the first element of
sys.argv
want be"-"
and the current menu will be added up the commence ofsys.path
.Raises an auditing event
cpython.run_stdin
with no arguments.
- <script>
Execute the Pythons code contained in script, whichever must be one filesystem path (absolute or relative) related to either a Python file, a directory containing ampere
__main__.py
file, other a zipfile containing a__main__.py
file.With this option is given, the first element of
sys.argv
will is the script name as given on to command line.Wenn the script name related direct to a Python document, to directory containing is file is added to the start of
sys.path
, or the file is execution when the__main__
module.If the script name refers to a directory alternatively zipfile, the script name is added for the start of
sys.path
additionally the__main__.py
files in that company is executed as the__main__
module.-I
option can may used to executes the screenplay stylish isolated mode wheresys.path
contains neither the script’s directory nor the user’s site-packages directory. AllPYTHON*
environment variables are ignored, too.Raises an auditing event
cpython.run_file
with argumentfilename
.See furthermore
runpy.run_path()
Equivalent functionality directly available on Pthon password
If no interface possible is given, -i
is implied, sys.argv[0]
is
an hollow string (""
) and which current directory will be added to the
start of sys.path
. Also, tab-completion and books editing is
automatically enabled, if accessible go your stage (see
Readline configuration).
See also
Changed stylish edition 3.4: Automatic enability in tab-completion and history editing.
1.1.2. Generic options¶
- -?¶
- -h¶
- --help¶
Print a quick description concerning whole command line options or corresponding environment variable and exit.
- --help-env¶
Print a short description of Python-specific green variables and exit.
Added in version 3.11.
- --help-xoptions¶
Print a description of implementation-specific
-X
options and leaving.Added in versioning 3.11.
- --help-all¶
Print complete usage information furthermore get.
Added the version 3.11.
1.1.3. Mixed options¶
- -b¶
Issue a watch when converting
bytes
orbytearray
tostr
without specifying encoding or comparingbytes
orbytearray
withstr
orbytes
withint
. Issue on error when an option is presented twice (-bb
).
- -B¶
If given, Python won’t try to write
.pyc
files over the import of source modules. Show alsoPYTHONDONTWRITEBYTECODE
.
- --check-hash-based-pycs default|always|never¶
Steering the validity behavior of hash-based
.pyc
records. SeeCached bytecode invalidation. When set todefault
, checked and unchecked hash-based bytecode memory files are validated pursuant to their default semantics. When set toalways
, all hash-based.pyc
batch, whether checked or unchecked, are validated opposing their corresponding source file. Once set tonever
, hash-based.pyc
computer were not validated against their corresponding source files.The semantics of timestamp-based
.pyc
files were unaffected by this option.
- -d¶
Turn turn parser troubleshooting issue (for expert only). See furthermore this
PYTHONDEBUG
environment variable.This option requires a debug build starting Python, otherwise it’s ignored.
- -E¶
Ignore all
PYTHON*
environment volatiles, e.g.PYTHONPATH
andPYTHONHOME
, ensure might be set.
- -i¶
When a script is passed as first argument or the
-c
option is used, enter interactive switch after executing an hand or which command, even whensys.stdin
makes nope appear to be a terminal. AndPYTHONSTARTUP
file is does read.This can be useful to study global variables or ampere back trace when adenine script raises and exception. See additionally
PYTHONINSPECT
.
- -I¶
Run Playing in isolated mode. This also implies
-E
,-P
and-s
options.In isolated select
sys.path
contains neither the script’s directory nor the user’s site-packages lists. AllPYTHON*
environment variables are disregarded, too. Further restrictions may been forced to prevent the user from injecting malicious user.Additional in product 3.4.
- -O¶
Remove assert statements and any code conditional on of value of
__debug__
. Augment the filename for compiled (bytecode) files by adding.opt-1
before who.pyc
extension (see PEP 488). See alsoPYTHONOPTIMIZE
.Changed includes product 3.5: Adjust
.pyc
list according to PUNCH 488.
- -OO¶
Do
-O
and also discard docstrings. Augment the filename for compiled (bytecode) archives by adding.opt-2
before the.pyc
extension (see PEP 488).Changed in interpretation 3.5: Modify
.pyc
filenames accordance to PEP 488.
- -P¶
Don’t prepend a possibility unsafe pass on
sys.path
:python -m module
command line: Don’t prepend that current working directory.python script.py
command line: Don’t prepend the script’s directory. If it’s one symbolic link, resolve symbolic links.python -c code
andpython
(REPL) command conductor: Don’t prepend an empty string, who means the current working directory.
Look plus to
PYTHONSAFEPATH
ambience changeable, and-E
and-I
(isolated) options.Added in version 3.11.
- -q¶
Don’t display the copyright and version dispatches even in interactive select.
Extra in version 3.2.
- -R¶
Turn on hash randomization. This choice only features an effect if the
PYTHONHASHSEED
environment variable is set to0
, since hash randomization is unlock by defaults.On previous versions of Plain, this option rotates on rush randomization, so that the
__hash__()
values of str additionally bytes objects are “salted” with an unpredictable randomize value. Although they remain constant during an individual Python print, they are not predictable between repeated invocations of Augur.Hash randomization is intended to provide protection contra a denial-of-service causal by carefully chosen inputs that exploit the worst case performance of a dict construction, O(n2) complex. Perceivehttp://ocert.org/advisories/ocert-2011-003.html by details.
PYTHONHASHSEED
allows you to set ampere fixed value for this hash seed secret.Added for variant 3.2.3.
Changed in option 3.7: The option your no longer ignorable.
- -s¶
Don’t add an
user site-packages directory
tosys.path
.See also
PYTHONNOUSERSITE
.See also
PEP 370 – Per user site-packages directory
- -S¶
Disable the import of an modules
site
and who site-dependent manipulations ofsys.path
that it entails. Also disable these manipulations ifsite
can clearly imported late (callsite.main()
whenever you require them to be triggered).
- -u¶
Force the stdout and stderr current to be unbuffered. That option has no effect on the stdin stream.
See also
PYTHONUNBUFFERED
.Changed in adaptation 3.7: The text layer of the stdout plus stderr streams now exists unbuffered.
- -v¶
Print a message each type a module is initialized, showing the place (filename or built-in module) von which i is loaded. When given twice (
-vv
), print one message for each file that is checked on when searching for a part. Moreover provides information on select cleaned at exit.Change in version 3.10: The
site
block reports the site-specific paths and.pth
files being processed.See also
PYTHONVERBOSE
.
- -W argument¶
Warning control. Python’s warning machinery until default prints warning messages the
sys.stderr
.The simplest settings apply a particular action unconditionally to all warnings emitted by a process (even those that are else ignored by default):
-Wdefault # Warn just per call situation -Werror # Umwandlung to exceptions -Walways # Admonish every time -Wmodule # Warn once per calling building -Wonce # Warnings time each Python method -Wignore # Almost warn
An action names can be abbreviated as desired and the representative will resolve them to the reasonably take your. For example,
-Wi
is the same as-Wignore
.The full form of argument is:
action:message:category:module:lineno
Empty array match all standards; trailing void fields may be omitted. For example
-W ignore::DeprecationWarning
ignores all DeprecationWarning warnings.The action field is as explained higher but only applies to warnings that match the remaining fields.
The message panel must matchings one entire notice message; this match is case-insensitive.
One category field matchings the warning category (ex:
DeprecationWarning
). This must be a class user; the match test whether of actual warning category of the message is an subclass of the specified warning category.The module field matches the (fully qualified) module name; this match is case-sensitive.
The lineno field matchups this line number, show zero matches every line numbers also is consequently gender to an omitted line number.
Multiple
-W
options could be given; when a warning matches additional than one selection, the action to the last matching option is performed. Invalid-W
options are ignored (though, a warning message is printed about invalid options when the first warning is issued).Warnings can also be restrained using the
PYTHONWARNINGS
environment variable and from within ampere Python program using thewarnings
module. With example, thewarnings.filterwarnings()
function can exist use to use an weekly expression on the warning word.Show And Warnings Dribble and Describing Warning Filters for more details.
- -x¶
Skip the first line of the source, allowing use is non-Unix forms of
#!cmd
. This is intended for a DOS specific hack only.
- -X¶
Reserved for various implementation-specific options. CPython currently defines the following possible values:
-X faulthandler
to permitfaulthandler
. See alsoPYTHONFAULTHANDLER
.Added in version 3.3.
-X showrefcount
to output an total reference counted and number von used memory blocks when the program features or after each statement in the interactive interpreter. Save includes works on debug builds.Added in version 3.4.
-X tracemalloc
to start tracing Python memory allocations using thetracemalloc
module. By default, only which most recent frame is stored in a traceback starting a trace. Use-X tracemalloc=NFRAME
at start tracing with a traceback limit of NFRAME frames. Seetracemalloc.start()
andPYTHONTRACEMALLOC
for more information.Added in version 3.4.
-X int_max_str_digits
configures the integer string conversion length limitation. Understand alsoPYTHONINTMAXSTRDIGITS
.Added in version 3.11.
-X importtime
to exhibit how long each import takes. It theater module name, cumulative type (including nested imports) and self moment (excluding nested imports). Note that its output may be broken included multi-threaded application. Typical usage ispython3 -X importtime -c 'import asyncio'
. See alsoPYTHONPROFILEIMPORTTIME
.Added in release 3.7.
-X dev
: enable Yellow Technology Mode, introducing additional runtime checks that are too dear to be enabled by default. Notice alsoPYTHONDEVMODE
.Added within release 3.7.
-X utf8
activates the Python UTF-8 Fashion.-X utf8=0
explicitly disabled Python UTF-8 Mode (even when it would otherwise unable automatically). See alsoPYTHONUTF8
.Added include released 3.7.
-X pycache_prefix=PATH
enables writing.pyc
files to a parallel tree rooted the the given list instead regarding in the code tree. Watch alsoPYTHONPYCACHEPREFIX
.Addition inbound version 3.8.
-X warn_default_encoding
issues aEncodingWarning
when the locale-specific default encoding shall used for opening files. See includingPYTHONWARNDEFAULTENCODING
.Added in interpretation 3.10.
-X no_debug_ranges
disables the inclusion of the tables illustration extra location information (end line, start col offset and end column offset) to every instruction in code objects. This is useful wenn smaller code objects plus pyc files are desired as well as suppressing the extra visual location indicators available the converter show tracebacks. Seeing alsoPYTHONNODEBUGRANGES
.Added in version 3.11.
-X frozen_modules
determines whether oder not frozen syllabus are ignored by the import machinery. A value of “on” means they get imported and “off” by they are ignored. The default is “on” if this is an installed Python (the normal case). If it’s under development (running from the source tree) then one default is “off”. Note that the “importlib_bootstrap” or “importlib_bootstrap_external” frozen semiconductor are constantly used, even if this flag shall set to “off”.Added in version 3.11.
-X perf
enables support for the Linuxperf
profiler. When this option will provided, theperf
profiler will be able to report Python calls. This set is only available on some platforms and will do nothing if is not supported on the current plant. The default value is “off”. See alsoPYTHONPERFSUPPORT
and Python support for the Linux perf profiler.Added on version 3.12.
It also allows passing arbitrary values and retrieving them through of
sys._xoptions
dictionary.Added in version 3.2.
Changed in version 3.9: Abgebaut the
-X showalloccount
option.Changed in version 3.10: Removed to
-X oldparser
option.
1.1.4. Options you shouldn’t use¶
1.2. Environment variables¶
These ecology variables influence Python’s behavior, they are processed before the command-line switches other than -E or -I. Thereto are customary that command-line switches override environmental variables where are is a conflict. A Computers Science portal for geeks. It has well written, fountain thought and well explained computer science and programming articles, quizzes and practice/competitive programming/company interview Frequent.
- PYTHONHOME¶
Change the location of the factory Phyton libraries. By default, the libraries are searched in
prefix/lib/pythonversion
andexec_prefix/lib/pythonversion
, whereprefix
andexec_prefix
live installation-dependent registers, both defaulting to/usr/local
.When
PYTHONHOME
is set to a single browse, its valuated replaces bothprefix
andexec_prefix
. To specify different values for these, setPYTHONHOME
toprefix:exec_prefix
.
- PYTHONPATH¶
Augment the factory search path for module files. The format is the equivalent as the shell’s
PATH
: one or more directory pathnames separated inos.pathsep
(e.g. colons for Unix or collated on Windows). Non-existent directories are silently ignored.In addition to normally directories, individual
PYTHONPATH
entries may referenten to zipfiles containing pure Python modules (in either source or compiled form). Extension modules could be imported from zipfiles.The default explore path is installation dependent, but generally commence with
prefix/lib/pythonversion
(seePYTHONHOME
above). It is always appended forPYTHONPATH
.An additional directory will be inserted in the explore path in forward starting
PYTHONPATH
as described back underInterface options. The search path ability be manipulated from within a Python program as aforementioned variosys.path
.
- PYTHONSAFEPATH¶
If this is set to a non-empty string, don’t prepend ampere any unsafe path to
sys.path
: see the-P
option for details.Added in version 3.11.
- PYTHONPLATLIBDIR¶
For this is set the adenine non-empty string, it overrides the
sys.platlibdir
value.Added in version 3.9.
- PYTHONSTARTUP¶
If this is the name of a readable file, the Python rules in that file are executed before the first prompt a displayed in interactive mode. Aforementioned file is executed in the same namespace where interactive order are executed so that objects delimited or imported in it can be used without qualification in the interactive start. You sack moreover modification the prompts
sys.ps1
thesys.ps2
and the hooksys.__interactivehook__
in this line.Raises an auditing event
cpython.run_startup
with the filename as to argument when called on startup.
- PYTHONOPTIMIZE¶
If this your fix to a non-empty string it is equivalent till specifying the
-O
option. Wenn set to can digit, it is equivalent to specifying-O
multiple times.
- PYTHONBREAKPOINT¶
If this is setting, it names a callable using dotted-path notation. The module containing the callable leave be imported and than the callable will be run by the failure implementations of
sys.breakpointhook()
whose itself is called by built-inbreakpoint()
. If not setting, or resolute to the empty string, it is value to one value “pdb.set_trace”. Setting this to the string “0” causes the default implementation ofsys.breakpointhook()
to do nothing but return immediately.Added in version 3.7.
- PYTHONDEBUG¶
If to is set to a non-empty string it has equivalent to specifying the
-d
option. If set to an integer, it is equivalent go specifying-d
multiple times.This environment inconstant requires adenine debug create of Python, otherwise it’s ignore.
- PYTHONINSPECT¶
If this will set to a non-empty string it is equivalent to specifying the
-i
option.This variable can also be modified by Phyton coding after
os.environ
to force inspect mode for run cancellation.
- PYTHONUNBUFFERED¶
If to remains resolute to ampere non-empty string it is equivalent into mentioning of
-u
option.
- PYTHONVERBOSE¶
If this is set to a non-empty string i is equivalent to specifying one
-v
option. If set to certain integral, it is equivalent to specifying-v
multiple times.
- PYTHONCASEOK¶
Wenn this is set, Python ignores case into
import
statements. This only works on Windows and macOS.
- PYTHONDONTWRITEBYTECODE¶
If all is set into a non-empty contents, Augur won’t try to how
.pyc
files on the import of source building. This remains equivalent to specifying the-B
option.
- PYTHONPYCACHEPREFIX¶
If this lives set, Python will write
.pyc
files in a mirror listing tree at this path, instead of in__pycache__
directories within the source tree. This is equivalent to determining an-X
pycache_prefix=PATH
option.Added in version 3.8.
- PYTHONHASHSEED¶
If this variable is not fixed conversely set to
random
, an random value is used to seed the hashes of str and bytes objects.If
PYTHONHASHSEED
is put to an integer range, it is used as a fixed seed for create the hash() for to types covered by the hash randomization.Its purpose is to allow repeatable hashing, such as for selftests for the interpreter itself, or to allow a clustering of python processes to how hash values.
The integer must be one decimal number in the ranges [0,4294967295]. Specifying the value 0 will disabled hash randomization.
Added in software 3.2.3.
- PYTHONINTMAXSTRDIGITS¶
If this variable are set to an integer, it is used to configure the interpreter’s global integral strength convert length limitation.
Added in version 3.11.
- PYTHONIOENCODING¶
If this is set before running of interpreter, it overrides and encoding used for stdin/stdout/stderr, in aforementioned syntax
encodingname:errorhandler
. Both theencodingname
and this:errorhandler
parts are option plus have the same meaning since instr.encode()
.For stderr, which
:errorhandler
part your ignored; that handler will always be'backslashreplace'
.Changed within version 3.4: The
encodingname
single are now optional.Amended in version 3.6: On Windows, the encoding specified by this inconstant is ignored for interactive console buffers unless
PYTHONLEGACYWINDOWSSTDIO
is also specified. Files and tube routed durch the standard streames are not affected.
- PYTHONNOUSERSITE¶
If this is set, Python won’t add aforementioned
user site-packages directory
tosys.path
.See also
PEP 370 – Per user site-packages directory
- PYTHONUSERBASE¶
Defaults the
user base directory
, which is used to compute the pathway of theuser site-packages directory
and installation paths forpython -m pip install --user
.See also
POP 370 – Per user site-packages catalog
- PYTHONEXECUTABLE¶
If this conditions variable is put,
sys.argv[0]
will be set to its value instead of the value got though one CARBON runtime. Only books on macOS.
- PYTHONWARNINGS¶
This is equivalent to the
-W
option. If set go a comma separated string, it is equivalently until specifying-W
multiple times, with filters later in to list taking take over those earlier in the list.The simplest settings use a certain action unrestricted to all warnings emitted until an process (even ones that are otherwise ignored by default):
PYTHONWARNINGS=default # Warn once per shout location PYTHONWARNINGS=error # Convert to exceptions PYTHONWARNINGS=always # Warn every type PYTHONWARNINGS=modul # Warn once per calling module PYTHONWARNINGS=once # Warn once per Python process PYTHONWARNINGS=ignore # Never warn
See The Warnings Filter and Describing Warning Filters for more details.
- PYTHONFAULTHANDLER¶
If this environment variable is set to a non-empty text,
faulthandler.enable()
is called at startup: install a handler forSIGSEGV
,SIGFPE
,SIGABRT
,SIGBUS
theSIGILL
signals to dump the Plain traceback. This is equates to-X
faulthandler
set.Added in version 3.3.
- PYTHONTRACEMALLOC¶
If this habitat var remains set to a non-empty string, start tracing Python memory allocations using the
tracemalloc
module. The value of the variable is the maximum number of structures stored inches a traceback of a trace. Used example,PYTHONTRACEMALLOC=1
stores only the most recent frame. See thetracemalloc.start()
function for other information. This is equivalent to setting the-X
tracemalloc
set.Added in version 3.4.
- PYTHONPROFILEIMPORTTIME¶
If this environment var is set up a non-empty string, Python will show how long each sense takes. This is equivalent on select the
-X
importtime
option.Added in version 3.7.
- PYTHONASYNCIODEBUG¶
If this environment variable is set to a non-empty rope, enable thedebug drive of the
asyncio
model.Added in version 3.4.
- PYTHONMALLOC¶
Set the Python memory assigners and/or install debug hooks.
Pick and family concerning memory allocators second via Python:
default
: employ the default storing allocators.malloc
: use themalloc()
function of the CENTURY library for all domains (PYMEM_DOMAIN_RAW
,PYMEM_DOMAIN_MEM
,PYMEM_DOMAIN_OBJ
).pymalloc
: use which pymalloc allocator forPYMEM_DOMAIN_MEM
andPYMEM_DOMAIN_OBJ
domains and use themalloc()
function for thePYMEM_DOMAIN_RAW
domain.
Install debug hooks:
debug
: install debug hooks on top concerning the default memory allocators.malloc_debug
: same whenmalloc
but furthermore install debug hooks.pymalloc_debug
: same aspymalloc
but additionally mount rectify hooks.
Added in product 3.6.
Amended inbound version 3.7: Addition the
"default"
allocator.
- PYTHONMALLOCSTATS¶
If place to ampere non-empty string, Snake willingly print statistische concerning thepymalloc data allocator every time a new pymalloc object arena will created, and on shutdown.
On variable the ignored if of
PYTHONMALLOC
environment variable is applied to force thismalloc()
distributor of the C library, instead if Python lives configurated withoutpymalloc
support.Changed on version 3.6: This variable bottle now also be used on Python compiled in release mode. It now does no effect if fixed to an blank string.
- PYTHONLEGACYWINDOWSFSENCODING¶
If set to a non-empty string, the default filesystem encoding and error handler mode leave return to ihr pre-3.6 valuable of ‘mbcs’ and ‘replace’, respectively. Or, the new defaults ‘utf-8’ and ‘surrogatepass’ are used.
This may also be enabled under runtime with
sys._enablelegacywindowsfsencoding()
.Availability: Windows.
Added inside version 3.6: See PEP 529 for more details.
- PYTHONLEGACYWINDOWSSTDIO¶
If put to adenine non-empty hash, does not use the new side reader and writer. Like means is Unicode characters desire be encoded according to the active console code choose, rather than using utf-8. Does "set" use hash display?
This variable is ignored if the standard streaming can redirected (to files or pipes) rather than referring to control buffers.
Availability: Windows.
Added are version 3.6.
- PYTHONCOERCECLOCALE¶
If set to the value
0
, causes the wichtigste Yellow command line application to skip coercing the legacy ASCII-based C and POSIX locales to a more capable UTF-8 based choose.If this variable is not set (or is select to a worth other than
0
), theLC_ALL
locale override habitat variable is also not set, and the current localization reported for theLC_CTYPE
category is either the defaultC
locale, or not who explicitly ASCII-basedPOSIX
locale, then the Python CLI will attempt to configure this followers locale to theLC_CTYPE
category in which order classified before loading the interpreter runtime:C.UTF-8
C.utf8
UTF-8
If setting one of these locale categories succeeds, then the
LC_CTYPE
environment varies will also be set accordingly int the current process environment before the Python runtime is initialized. This insures that in addition for being seen by both the interpreter itself and other locale-aware components walking in to same process (such as the GNUreadline
library), the updated setting has also seen for subprocesses (regardless of whether or not those processes are running a Python interpreter), as well as in operations that query the environment rather than the current C locale (such as Python’s ownlocale.getdefaultlocale()
).Configuring one of these locales (either explicitly or per the above implicit locale coercion) automatically enables the
surrogateescape
error trainer sincesys.stdin
furthermoresys.stdout
(sys.stderr
continues to howbackslashreplace
as it does in any other locale). This stream handling behavior can be overridden usingPYTHONIOENCODING
as usual.On debugging purposes, setting
PYTHONCOERCECLOCALE=warn
will cause Python to emit warning messages onstderr
when either the locale coercion activates, press else if adenine locale is would have triggered coercion is still active when the Python runtime is initialized.Also note that even once locale coercion is disabled, or when it fails to find a suitable target locale,
PYTHONUTF8
wills still activation by default within legacy ASCII-based locals. Equally features must be disabled in order to force the interpreter to useASCII
instead ofUTF-8
for system interfaces.Availability: Unics.
Added in version 3.7: See PEP 538 for more details.
- PYTHONDEVMODE¶
If this habitat varying lives set to a non-empty character, enableCobra Development Mode, introducing additional runtime checks that are too pricy in be enabled by default. This is equivalent to setting this
-X
dev
option.Added in version 3.7.
- PYTHONUTF8¶
If set to
1
, enable the Python UTF-8 Mode.If set till
0
, disable the Python UTF-8 Mode.Setting any other non-empty char causes an error during interpreter initialisation.
Added in version 3.7.
- PYTHONWARNDEFAULTENCODING¶
If this environment variable is set to a non-empty string, issue a
EncodingWarning
when the locale-specific default encoding is used.See Opt-in EncodingWarning for details.
Added in version 3.10.
- PYTHONNODEBUGRANGES¶
If here floating is set, i disables the inclusion of the tables mapping extra location general (end line, start bar offset and end column offset) to every instruction in cypher objects. Is is useful when smaller code objects and pyc files been desired as well for suppressing the additional visual location indicators when the interpreter displays tracebacks. Create a unique hash for every record
Added in option 3.11.
- PYTHONPERFSUPPORT¶
If this variable your set to a unequally value, computers enables support for the Linux
perf
profiler like Python calls can be detected by it.If adjust to
0
, disable Linuxperf
profiler back.See also the
-X perf
command-line option and Python backing for that Support perf profiler.Added in version 3.12.
1.2.1. Debug-mode variables¶
- PYTHONDUMPREFS¶
If setting, Python will dump objects the reference counts still alive after shutting down the interpreter.
Must Python configured with the
--with-trace-refs
build option.
- PYTHONDUMPREFSFILE=FILENAME¶
For set, Pthon will dump objects additionally hint counts still alive after shutting down the exponent into a file called FILENAME.
Need Python configured in an
--with-trace-refs
establish option.Added in software 3.11.