PYTHON(1)
PYTHON(1) ๐
General Commands Manual โ yep bestie, you're reading the python man page โจ
โจ NAME โจ
python โ an interpreted, interactive, object-oriented programming language ๐๐
๐ธ SYNOPSIS ๐ธ
python [ -B ] [ -b ] [ -d ] [ -E ] [ -h ] [ -i ] [ -I ]
[ -m module-name ] [ -q ] [ -R ] [ -O ] [ -OO ] [ -P ] [ -s ] [ -S ] [ -u ]
[ -v ] [ -V ] [ -W argument ] [ -x ] [ -X option ] [ -? ]
[ --check-hash-based-pycs default | always | never ]
[ --help ] [ --help-env ] [ --help-xoptions ] [ --help-all ]
[ -c command | script | - ] [ arguments ]
๐ฆ DESCRIPTION ๐ฆ
Okay so Python is an interpreted, interactive, object-oriented programming language, and the way it combines remarkable power with very clear syntax?? genuinely iconic, no notes ๐ โจ
Want an intro to programming in Python? Go read the Python Tutorial ๐ The Python Library Reference is where all the built-in and standard types, constants, functions and modules get documented. And finally, the Python Reference Manual describes the syntax and semantics of the core language in (perhaps too) much detail ๐ญ โ literally, it does not hold back.
These documents may be located via the INTERNET RESOURCES below ๐ and they may be installed on your system as well, so check around, bestie ๐ซถ
Python's basic power can be extended with your own modules written in C or C++ ๐ฅ On most systems such modules may be dynamically loaded. Python is also adaptable as an extension language for existing applications โ see the internal documentation for hints ๐ง
Documentation for installed Python modules and packages can be viewed by running the pydoc program ๐โจ
โฆand there's more, bestie โ keep reading ๐
โจ COMMAND LINE OPTIONS โจ
okay bestie, this is the main character section. every flag below is a little switch you can flip when you run Python, and yes, you need to know all of them because iykyk. let's go ๐
-Bโ don't write.pycfiles on import. see alsoPYTHONDONTWRITEBYTECODE. no cap, this is the "keep my folders clean" vibe. โจ-bโ issue warnings aboutstr(bytes_instance),str(bytearray_instance)and comparingbytes/bytearraywithstr. (-bb: issue errors) ๐จ-c commandโ specify the command to execute (see next section). this terminates the option list โ following options are passed as arguments to the command. periodt. ๐--check-hash-based-pycs modeโ configure how Python evaluates the up-to-dateness of hash-based.pycfiles. ๐-dโ turn on parser debugging output (for expert only, depending on compilation options). lowkey not for the faint of heart. ๐-Eโ ignore environment variables likePYTHONPATHandPYTHONHOMEthat modify the behavior of the interpreter. ๐-h,-?,--helpโ prints the usage for the interpreter executable and exits. the classic "help me bestie" move. ๐ซถ--help-envโ prints help about Python-specific environment variables and exits. ๐ธ--help-xoptionsโ prints help about implementation-specific-Xoptions and exits. โจ--help-allโ prints complete usage information and exits. the whole encyclopedia, no cap. ๐-iโ when a script is passed as first argument or the-coption is used, enter interactive mode after executing the script or the command. it does not read the$PYTHONSTARTUPfile. this can be useful to inspect global variables or a stack trace when a script raises an exception. it's giving detective mode. ๐-Iโ run Python in isolated mode. this also implies-E,-Pand-s. in isolated modesys.pathcontains neither the script's directory nor the user'ssite-packagesdirectory. allPYTHON*environment variables are ignored, too. further restrictions may be imposed to prevent the user from injecting malicious code. ๐ก๏ธ-m module-nameโ searchessys.pathfor the named module and runs the corresponding.pyfile as a script. this terminates the option list โ following options are passed as arguments to the module. ๐-Oโ removeassertstatements and any code conditional on the value of__debug__; augment the filename for compiled (bytecode) files by adding.opt-1before the.pycextension. optimizing era. โจ-OOโ do-Oand also discard docstrings; change the filename for compiled (bytecode) files by adding.opt-2before the.pycextension. double optimized, double iconic. ๐-Pโ don't automatically prepend a potentially unsafe path tosys.pathsuch as the current directory, the script's directory or an empty string. see also thePYTHONSAFEPATHenvironment variable. safety first, bestie. ๐ก๏ธ-qโ do not print the version and copyright messages. these messages are also suppressed in non-interactive mode. quiet luxury. ๐คซ-Rโ turn on hash randomization. this option only has an effect if thePYTHONHASHSEEDenvironment variable is set to0, since hash randomization is enabled by default. ๐ฅ-sโ don't add user site directory tosys.path. simple, clean. ๐งผ-Sโ disable the import of the modulesiteand the site-dependent manipulations ofsys.paththat it entails. also disable these manipulations ifsiteis explicitly imported later. ๐ซ-uโ force thestdoutandstderrstreams to be unbuffered. this option has no effect on thestdinstream. unbuffered and unbothered. ๐-vโ print a message each time a module is initialized, showing the place (filename or built-in module) from which it is loaded. when given twice, print a message for each file that is checked for when searching for a module. also provides information on module cleanup at exit. verbose main character energy. ๐ฃ๏ธ-V,--versionโ prints the Python version number of the executable and exits. when given twice, print more information about the build. ๐-W argumentโ warning control. Python's warning machinery by default prints warning messages tosys.stderr.
the simplest settings apply a particular action unconditionally to all warnings emitted by a process (even those that are otherwise ignored by default):
-Wdefault # Warn once per call location
-Werror # Convert to exceptions
-Walways # Warn every time
-Wall # Same as -Walways
-Wmodule # Warn once per calling module
-Wonce # Warn once per Python process
-Wignore # Never warn
the action names can be abbreviated as desired and the interpreter will resolve them to the appropriate action name. for example, -Wi is the same as -Wignore .
the full form of argument is:
action:message:category:module:lineno
empty fields match all values; trailing empty fields may be omitted. for example -W ignore::DeprecationWarning ignores all DeprecationWarning warnings.
- the action field is as explained above but only applies to warnings that match the remaining fields.
- the message field must match the start of the warning message; this match is case-insensitive.
- the category field matches the warning category (ex:
"DeprecationWarning"). this must be a class name; the match test whether the actual warning category of the message is a subclass of the specified warning category. - the module field matches the (fully-qualified) module name; this match is case-sensitive.
- the lineno field matches the line number, where zero matches all line numbers and is thus equivalent to an omitted line number.
multiple -W options can be given; when a warning matches more than one option, the action for 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 controlled using the PYTHONWARNINGS environment variable and from within a Python program using the warnings module. for example, the warnings.filterwarnings() function can be used to use a regular expression on the warning message. ๐จ
-X optionโ set implementation-specific option. the following options are available:-X cpu_count=Nโ override the return value ofos.cpu_count();-X cpu_count=defaultcancels overriding; alsoPYTHON_CPU_COUNT. ๐ง-X devโ enable CPython's "development mode", introducing additional runtime checks which are too expensive to be enabled by default. it will not be more verbose than the default if the code is correct: new warnings are only emitted when an issue is detected. effect of the developer mode:- add default warning filter, as
-W default - install debug hooks on memory allocators: see the
PyMem_SetupDebugHooks()C function - enable the
faulthandlermodule to dump the Python traceback on a crash - enable
asynciodebug mode - set the
dev_modeattribute ofsys.flagstoTrue io.IOBasedestructor logsclose()exceptions
- add default warning filter, as
-X importtimeโ show how long each import takes. it shows module name, cumulative time (including nested imports) and self time (excluding nested imports). note that its output may be broken in multi-threaded application. typical usage ispython3 -X importtime -c 'import asyncio'. โฑ๏ธ-X faulthandlerโ enablefaulthandler. ๐ฅ-X frozen_modules=[on|off]โ whether or not frozen modules should be used. the default is"on"(or"off"if you are running a local build). ๐ง-X gil=[0|1]โ enable (1) or disable (0) the GIL; alsoPYTHON_GIL. only available in builds configured with--disable-gil. ๐งต-X int_max_str_digits=numberโ limit the size ofint<->strconversions. this helps avoid denial of service attacks when parsing untrusted data. the default issys.int_info.default_max_str_digits.0disables. ๐ข-X no_debug_rangesโ disable the inclusion of the tables mapping extra location information (end line, start column offset and end column offset) to every instruction in code objects. this is useful when smaller code objects and pyc files are desired as well as suppressing the extra visual location indicators when the interpreter displays tracebacks. ๐-X perfโ support the Linux"perf"profiler; alsoPYTHONPERFSUPPORT=1. ๐-X perf_jitโ support the Linux"perf"profiler with DWARF support; alsoPYTHON_PERF_JIT_SUPPORT=1. ๐ฅ-X presite=MODโ import this module beforesite; alsoPYTHON_PRESITE. this only works on debug builds. ๐งช-X pycache_prefix=PATHโ enable writing.pycfiles to a parallel tree rooted at the given directory instead of to the code tree. ๐ณ-X showrefcountโ output the total reference count and number of used memory blocks when the program finishes or after each statement in the interactive interpreter. this only works on debug builds. ๐-X tracemallocโ start tracing Python memory allocations using thetracemallocmodule. by default, only the most recent frame is stored in a traceback of a trace. use-X tracemalloc=NFRAMEto start tracing with a traceback limit ofNFRAMEframes. ๐ง-X utf8โ enable UTF-8 mode for operating system interfaces, overriding the default locale-aware mode.-X utf8=0explicitly disables UTF-8 mode (even when it would otherwise activate automatically). seePYTHONUTF8for more details. ๐-X warn_default_encodingโ enable opt-inEncodingWarningfor'encoding=None'. โ ๏ธ
-xโ skip the first line of the source. this is intended for a DOS specific hack only.
warning: the line numbers in error messages will be off by one! ๐ญ
๐ INTERPRETER INTERFACE ๐
okay bestie so the interpreter interface is giving very UNIX shell energy. Let's break it down:
- when it's called with standard input connected to a tty device, it prompts you for commands and runs them until it reads an EOF
- when it's called with a file name argument or with a file as standard input, it reads and executes a script from that file
- when it's called with
-ccommand, it executes the Python statement(s) given as command
and heads up, command can contain multiple statements separated by newlines. also โ leading whitespace is significant in Python statements! ๐ like, do not come for Python's indentation, it's iconic and it's staying.
in non-interactive mode, the entire input is parsed before it is executed. periodt.
If available, the script name and additional arguments thereafter get passed to the script in the Python variable sys.argv, which is a list of strings (you gotta import sys first to access it, no cap). Details:
- if no script name is given,
sys.argv[0]is an empty string - if
-cis used,sys.argv[0]contains the string'-c'
note that options interpreted by the Python interpreter itself are not placed in sys.argv. ๐ซถ
In interactive mode, the primary prompt is >>>; the second prompt (which shows up when a command isn't complete) is .... you can change the prompts by assigning to sys.ps1 or sys.ps2. slay, customizable.
The interpreter quits when it reads an EOF at a prompt. When an unhandled exception occurs, a stack trace is printed and control returns to the primary prompt; in non-interactive mode, the interpreter exits after printing the stack trace. The interrupt signal raises the KeyboardInterrupt exception; other UNIX signals are not caught (except that SIGPIPE is sometimes ignored, in favor of the IOError exception). Error messages are written to stderr.
๐ธ FILES AND DIRECTORIES ๐ธ
these are subject to difference depending on local installation conventions, lowkey. ${prefix} and ${exec_prefix} are installation-dependent and should be interpreted as for GNU software; they may be the same. The default for both is /usr/local.
${exec_prefix}/bin/pythonโ Recommended location of the interpreter. ๐${prefix}/lib/python<version>${exec_prefix}/lib/python<version>โ Recommended locations of the directories containing the standard modules. ๐ง${prefix}/include/python<version>${exec_prefix}/include/python<version>โ Recommended locations of the directories containing the include files needed for developing Python extensions and embedding the interpreter. ๐ฆ
โจ ENVIRONMENT VARIABLES โจ
the moment you've all been waiting for, bestie. so many little switches. ๐
PYTHONASYNCIODEBUGโ If this environment variable is set to a non-empty string, enable the debug mode of theasynciomodule.PYTHON_BASIC_REPLโ If this variable is set to any value, the interpreter will not attempt to load the Python-based REPL that requirescursesandreadline, and will instead use the traditional parser-based REPL.PYTHONBREAKPOINTโ If this environment variable is set to0, it disables the default debugger. It can be set to the callable of your debugger of choice.PYTHONCOERCECLOCALEโ If set to the value0, causes the main Python command line application to skip coercing the legacy ASCII-based C and POSIX locales to a more capable UTF-8 based alternative.PYTHON_COLORSโ If this variable is set to1, the interpreter will colorize various kinds of output. Setting it to0deactivates this behavior. ๐ (iconic tbh)PYTHON_CPU_COUNTโ If this variable is set to a positive integer, it overrides the return values ofos.cpu_countandos.process_cpu_count.
See also the -X cpu_count option.
PYTHONDEBUGโ If this is set to a non-empty string it is equivalent to specifying the-doption. If set to an integer, it is equivalent to specifying-dmultiple times.PYTHONEXECUTABLEโ If this environment variable is set,sys.argv[0]will be set to its value instead of the value got through the C runtime. Only works on Mac OS X.PYTHONFAULTHANDLERโ If this environment variable is set to a non-empty string,faulthandler.enable()is called at startup: install a handler forSIGSEGV,SIGFPE,SIGABRT,SIGBUSandSIGILLsignals to dump the Python traceback.
This is equivalent to the -X faulthandler option.
PYTHON_FROZEN_MODULESโ If this variable is set toonoroff, it determines whether or not frozen modules are ignored by the import machinery. A value ofonmeans they get imported andoffmeans they are ignored. The default isonfor non-debug builds (the normal case) andofffor debug builds.
See also the -X frozen_modules option.
PYTHON_GILโ If this variable is set to1, the global interpreter lock (GIL) will be forced on. Setting it to0forces the GIL off. Only available in builds configured with--disable-gil.
This is equivalent to the -X gil option.
PYTHON_HISTORYโ This environment variable can be used to set the location of a history file (on Unix, it is~/.python_historyby default).PYTHONNODEBUGRANGESโ If this variable is set, it disables the inclusion of the tables mapping extra location information (end line, start column offset and end column offset) to every instruction in code objects. This is useful when smaller code objects andpycfiles are desired as well as suppressing the extra visual location indicators when the interpreter displays tracebacks.PYTHONDONTWRITEBYTECODEโ If this is set to a non-empty string it is equivalent to specifying the-Boption (don't try to write.pycfiles).PYTHONDEVMODEโ If this environment variable is set to a non-empty string, enable Python's "development mode", introducing additional runtime checks that are too expensive to be enabled by default.
This is equivalent to the -X dev option.
PYTHONHASHSEEDโ If this variable is set to"random", a random value is used to seed the hashes ofstrandbytesobjects.
If PYTHONHASHSEED is set to an integer value, it is used as a fixed seed for generating the hash() of the 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 cluster of python processes to share hash values.
The integer must be a decimal number in the range [0,4294967295]. Specifying the value 0 will disable hash randomization.
PYTHONHOMEโ Change the location of the standard Python libraries. By default, the libraries are searched in${prefix}/lib/python<version>and${exec_prefix}/lib/python<version>, where${prefix}and${exec_prefix}are installation-dependent directories, both defaulting to/usr/local. When$PYTHONHOMEis set to a single directory, its value replaces both${prefix}and${exec_prefix}. To specify different values for these, set$PYTHONHOMEto${prefix}:${exec_prefix}.PYTHONINSPECTโ If this is set to a non-empty string it is equivalent to specifying the-ioption.PYTHONINTMAXSTRDIGITSโ Limit the maximum digit characters in anintvalue when converting from a string and when converting anintback to astr. A value of0disables the limit. Conversions to or from bases 2, 4, 8, 16, and 32 are never limited.
This is equivalent to the -X int_max_str_digits=NUMBER option.
PYTHONIOENCODINGโ If this is set before running the interpreter, it overrides the encoding used for stdin/stdout/stderr, in the syntaxencodingname:errorhandlerTheerrorhandlerpart is optional and has the same meaning as instr.encode. For stderr, theerrorhandlerpart is ignored; the handler will always beยดbackslashreplaceยด.PYTHONMALLOCโ Set the Python memory allocators and/or install debug hooks. The available memory allocators aremallocandpymalloc. The available debug hooks aredebug,malloc_debug, andpymalloc_debug.
When Python is compiled in debug mode, the default is pymalloc_debug and the debug hooks are automatically used. Otherwise, the default is pymalloc.
PYTHONMALLOCSTATSโ If set to a non-empty string, Python will print statistics of thepymallocmemory allocator every time a newpymallocobject arena is created, and on shutdown.
This variable is ignored if the $PYTHONMALLOC environment variable is used to force the malloc(3) allocator of the C library, or if Python is configured without pymalloc support.
PYTHONNOUSERSITEโ If this is set to a non-empty string it is equivalent to specifying the-soption (Don't add the user site directory tosys.path).PYTHONOPTIMIZEโ If this is set to a non-empty string it is equivalent to specifying the-Ooption. If set to an integer, it is equivalent to specifying-Omultiple times.PYTHONPATHโ Augments the default search path for module files. The format is the same as the shell's$PATH: one or more directory pathnames separated by colons. Non-existent directories are silently ignored. The default search path is installation dependent, but generally begins with${prefix}/lib/python<version>(seePYTHONHOMEabove). The default search path is always appended to$PYTHONPATH. If a script argument is given, the directory containing the script is inserted in the path in front of$PYTHONPATH. The search path can be manipulated from within a Python program as the variablesys.path.PYTHON_PERF_JIT_SUPPORTโ If this variable is set to a nonzero value, it enables support for the Linuxperfprofiler so Python calls can be detected by it using DWARF information. Setting to0disables.
See also the -X perf_jit option.
PYTHONPERFSUPPORTโ If this variable is set to a nonzero value, it enables support for the Linuxperfprofiler so Python calls can be detected by it. Setting to0disables.
See also the -X perf option.
PYTHONPLATLIBDIRโ Overridesys.platlibdir.PYTHONPROFILEIMPORTTIMEโ If this environment variable is set to a non-empty string, Python will show how long each import takes. This is exactly equivalent to setting-X importtimeon the command line. โฑ๏ธ
and now, the rest of the env vars, bestie โ these are the ones that fine-tune how Python moves. no cap, they're iconic. ๐
PYTHONPYCACHEPREFIXโ if you set this, Python writes its.pycfiles into a mirror directory tree at this path instead of dropping__pycache__directories all over your source tree. it's literally the same as passing-X pycache_prefix=PATH. periodt. โจPYTHONSAFEPATHโ set this to any non-empty string and Python will not automatically prepend a potentially unsafe path tosys.pathโ like the current directory, the script's directory, or an empty string. also peep the-Poption. safety first, bestie. ๐ก๏ธPYTHONSTARTUPโ if this is the name of a readable file, the Python commands in that file get executed before the first prompt is displayed in interactive mode. the file runs in the same name space where interactive commands are executed, so any objects you define or import in it can be used without qualification in your interactive session. you can also change the promptssys.ps1andsys.ps2in this file. it's giving custom startup glow-up. ๐ธPYTHONTRACEMALLOCโ if this environment variable is set to a non-empty string, Python starts tracing memory allocations using thetracemallocmodule. the value of the variable is the maximum number of frames stored in a traceback of a trace. for example,PYTHONTRACEMALLOC=1stores only the most recent frame. memory tea, spilled. ๐ตPYTHONUNBUFFEREDโ if set to a non-empty string, it's equivalent to specifying the-uoption. unbuffered and unbothered. ๐PYTHONUSERBASEโ defines the user base directory, which is used to compute the path of the user site-packages directory and installation paths forpython -m pip install --user. your personal install zone, slay. ๐PYTHONUTF8โ set to1to enable the Python "UTF-8 Mode". set to0to disable. simple as that. ๐PYTHONVERBOSEโ if set to a non-empty string, it's equivalent to specifying the-voption. if set to an integer, it's equivalent to specifying-vmultiple times. chatty Python, activated. ๐ฃ๏ธPYTHONWARNDEFAULTENCODINGโ if set to a non-empty string, Python issues anEncodingWarningwhen the locale-specific default encoding is used. warning you before things get weird. โ ๏ธPYTHONWARNINGSโ if set to a comma-separated string, it's equivalent to specifying the-Woption for each separate value. warning spam, but make it organized. ๐ข
๐ Debug-mode variables ๐
Setting these variables only has an effect in a debug build of Python, that is, if Python was configured with the --with-pydebug build option. so unless you're in debug mode, these are just cute decorations. ๐
PYTHONDUMPREFSโ if this environment variable is set, Python will dump objects and reference counts still alive after shutting down the interpreter. ghost objects, exposed. ๐ปPYTHONDUMPREFSFILEโ if set, Python will dump objects and reference counts still alive after shutting down the interpreter into a file under the path given as the value to this environment variable. now with file output. ๐PYTHON_PRESITEโ if this variable is set to a module, that module will be imported early in the interpreter lifecycle, before thesitemodule is executed, and before the__main__module is created. this only works on debug builds. it's equivalent to the-X presite=moduleoption. early bird module. ๐ฆ
๐ AUTHOR ๐
The Python Software Foundation: https://www.python.org/psf/ โ the literal icons behind Python. bow down. ๐ซถ
๐ INTERNET RESOURCES ๐
need more Python in your life? here's where to find the whole squad:
- Main website:
https://www.python.org/ - Documentation:
https://docs.python.org/ - Developer resources:
https://devguide.python.org/ - Downloads:
https://www.python.org/downloads/ - Module repository:
https://pypi.org/ - Newsgroups:
comp.lang.python,comp.lang.python.announce
๐ LICENSING ๐
Python is distributed under an Open Source license. See the file "LICENSE" in the Python source distribution for information on terms & conditions for accessing and otherwise using Python and for a DISCLAIMER OF ALL WARRANTIES. read the fine print, bestie. it matters. ๐
and that's the whole manpage, bestie โ this was PYTHON(1) ๐ โจ no cap, you're now a Python env var expert. go slay. ๐๐
๐ฆ where this page comes from
- epel 10: python3.13 3.13.16-1.el10_3 ยท Python-2.0.1
- epel 9: python3.13 3.13.16-1.el9 ยท Python-2.0.1
- fedora 43: python3.13 3.13.16-1.fc43 ยท Python-2.0.1
- fedora 43: python3.13 3.13.16-1.fc43 ยท Python-2.0.1
- fedora 44: python3.13 3.13.16-1.fc44 ยท Python-2.0.1
- fedora 44: python3.13 3.13.16-1.fc44 ยท Python-2.0.1
- nixos 26.05: python3-minimal 3.13.17
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms