PYTHON(1)
PYTHON(1) ๐
okay bestie, welcome to the General Commands Manual for python. buckle up, this one's a whole personality ๐
โจ NAME โจ
python โ an interpreted, interactive, object-oriented programming language ๐๐
yes that's the whole thing. she's a language, she interprets, she interacts, she's object-oriented, she ate.
๐ธ 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 ]
it's giving "the whole alphabet walked in and sat down" ngl. every single one of those is explained below, no skips, no shortcuts ๐ซถ
๐ฆ DESCRIPTION ๐ฆ
Python is an interpreted, interactive, object-oriented programming language that combines remarkable power with very clear syntax. iconic combo honestly โ like being both gorgeous and smart ๐ โจ
For an intro to programming in Python, go peek at the Python Tutorial. The Python Library Reference is where you'll find the built-in and standard types, constants, functions and modules all documented. And finally, the Python Reference Manual describes the syntax and semantics of the core language in โ and I quote, bestie โ (perhaps too) much detail ๐ญ. These documents can be found via the INTERNET RESOURCES below, and they might already be installed on your system too, no biggie.
Python's basic power can be extended with your own modules written in C or C++ ๐ฅ. On most systems, those modules can be dynamically loaded. Python is also adaptable as an extension language for existing applications โ see the internal documentation for hints, iykyk ๐
Want to read docs for installed Python modules and packages? Just run the pydoc program. that's it. that's the tip. ๐
more parts coming bestie, don't go anywhere ๐
โจ COMMAND LINE OPTIONS โจ
Okay bestie, this is the part where the real fun starts โ every single flag you can throw at python3. Grab a snack, we're going through all of them. ๐
-Bโ bestie do NOT write.pycfiles on import. That's it, that's the whole vibe. (Also peepPYTHONDONTWRITEBYTECODEif you want this energy everywhere.)-bโ throws warnings at you aboutstr(bytes_instance),str(bytearray_instance), and comparing bytes/bytearray with str. Add another one โ-bbโ and it stops being a warning and becomes a whole error. Glow up. ๐-ccommand โ run the command you type in here (more on that in the next section, iykyk). Heads up: this ends the option list, so everything after it gets passed as arguments to your command. Lowkey important.--check-hash-based-pycsmode โ controls how Python decides whether hash-based.pycfiles are up to date. Vibe check for your bytecode, basically.-dโ turns on parser debugging output. Experts only, and only if your build even has it compiled in. Not for the faint of heart fr.-Eโ ignore environment variables likePYTHONPATHandPYTHONHOMEthat mess with how the interpreter behaves. Boundaries, periodt.-h,-?,--helpโ prints the usage for the interpreter executable and dips. Classic.--help-envโ prints help about Python-specific environment variables and exits. ๐ง--help-xoptionsโ prints help about implementation-specific-Xoptions and exits.--help-allโ prints the complete usage information and exits. The full lore drop.-iโ when a script is passed as the first argument, or you used-c, this drops you into interactive mode after the script or command runs. It does not read the$PYTHONSTARTUPfile. Absolute lifesaver for inspecting global variables or getting a stack trace when a script raises an exception. ๐-Iโ isolated mode, babes. This implies-E,-Pand-s. In isolated mode,sys.pathcontains neither the script's directory nor the user's site-packages directory. AllPYTHON*environment variables are ignored too. And honestly? Further restrictions may be imposed to stop the user from injecting malicious code. She's locked down. ๐ฅ-mmodule-name โ searchessys.pathfor the module you named and runs the matching.pyfile as a script. Just like-c, this terminates the option list โ everything after gets passed as arguments to the module.-Oโ removesassertstatements and any code conditional on the value of__debug__; it also augments the filename for compiled (bytecode) files by adding.opt-1before the.pycextension.-OOโ does everything-Odoes AND discards docstrings; changes the compiled (bytecode) filename by adding.opt-2before the.pycextension. Double stripped. ๐-Pโ don't automatically prepend a potentially unsafe path tosys.path, like the current directory, the script's directory, or an empty string. See also thePYTHONSAFEPATHenvironment variable.-qโ do not print the version and copyright messages. (They're suppressed in non-interactive mode anyway, so consider this your quiet luxury era.)-Rโ turn on hash randomization. Ngl this only does anything ifPYTHONHASHSEEDis set to0, because hash randomization is already enabled by default. Iconic but mostly ceremonial.-sโ don't add the user site directory tosys.path.-Sโ disable the import of the modulesiteand the site-dependent manipulations ofsys.paththat come with it. And yes, it also disables those manipulations ifsitegets explicitly imported later.-uโ force thestdoutandstderrstreams to be unbuffered. Quick note: this has no effect on thestdinstream.-vโ prints a message every time a module is initialized, showing the place (filename or built-in module) from which it's loaded. Give it twice and you get a message for every single file checked while searching for a module. It also spills the tea on module cleanup at exit. So chatty, we love her. ๐ซถ-V,--versionโ prints the Python version number of the executable and exits. Give it twice and you get more information about the build.-Wargument โ 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 however you want 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 tests 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.
-Xoption โ set an implementation-specific option. The following options are available:-X cpu_count=Nโ override the return value ofos.cpu_count().-X cpu_count=defaultcancels the overriding. See alsoPYTHON_CPU_COUNT.-X devโ enable CPython's "development mode", introducing additional runtime checks that are too expensive to be on 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 asyncio debug 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 importtime=2 enables additional output that indicates when an imported module has already been loaded. In such cases, the string cached will be printed in both time columns.
-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. See alsoPYTHON_GIL. Only available in builds configured with--disable-gil.-X int_max_str_digits=numberโ limit the size of intโstr conversions. 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. See alsoPYTHONPERFSUPPORT=1.-X perf_jitโ support the Linux "perf" profiler with DWARF support. See alsoPYTHON_PERF_JIT_SUPPORT=1.-X presite=MODโ import this module beforesite. See 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 bestie: with -x, the line numbers in error messages will be off by one! ๐ญ Keep that in mind before you go blaming the wrong line.
๐ธ INTERPRETER INTERFACE ๐ธ
okay so bestie, the way the interpreter talks to you is literally giving UNIX shell energy, no cap. Here's the tea ๐ต:
- when you call it with standard input connected to a tty device, it prompts you for commands and executes them until it reads an EOF ๐ซถ
- when you call it with a file name argument, or with a file as standard input, it reads and executes a script from that file
- when you call it with
-ccommand, it executes the Python statement(s) given as command. and command can absolutely contain multiple statements separated by newlines ๐
โ ๏ธ Leading whitespace is significant in Python statements! do not be out here deleting your indentation bestie, it WILL humble you ๐ญ
also: in non-interactive mode, the entire input is parsed before it is executed. like, all of it, first, then it runs. that's just how it is ๐
if available, the script name and any additional arguments after it get passed to your script in the Python variable sys.argv, which is a list of strings (and yes you must first import sys to be able to access it, bestie, it's not just vibing in your namespace for free ๐).
- if no script name is given,
sys.argv[0]is an empty string - if
-cis used,sys.argv[0]contains the string'-c'
and heads up: options interpreted by the Python interpreter itself are not placed in sys.argv. they're not invited to that party โจ
in interactive mode, the primary prompt is >>>' and the second prompt (the one that shows up when a command is not complete) is ...'. you can change these prompts by assignment to sys.ps1 or sys.ps2 โ main character customization, honestly ๐
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 ๐. but in non-interactive mode, the interpreter exits after printing the stack trace. different vibes entirely.
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. that's just where they live ๐
๐ FILES AND DIRECTORIES ๐
these are subject to difference depending on local installation conventions, so don't come for them if yours look different, bestie. ${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. that's the one, the icon, the moment โญ${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 โจ
okay this is the big one, the whole mood board of env vars. every single one, in order, no skipping ๐
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. retro vibes only ๐ฅ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. color is a lifestyle ๐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. โ ๏ธ niche but iconic
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 bases2,4,8,16, and32are 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 forstdin/stdout/stderr, in the syntaxencodingname:errorhandler. theerrorhandlerpart is optional and has the same meaning as instr.encode. forstderr, theerrorhandlerpart is ignored; the handler will always bebackslashreplace๐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 new pymalloc object 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. short, sweet, iconic ๐PYTHONPROFILEIMPORTTIMEโ if this environment variable is set to1, Python will show how long each import takes. if set to2, Python will include output for imported modules that have already been loaded. this is exactly equivalent to setting-X importtimeon the command line โฑ๏ธ
okay bestie we're so back ๐ </p> the env var list is still going, and honestly? it ate. keep scrolling, we're almost at the finish line ๐
PYTHONPYCACHEPREFIXโ set this and Python stops scattering.pycfiles into__pycache__folders all over your source tree (so messy of it). Instead it writes them into a mirror directory tree at the path you give it. Same energy as passing-X pycache_prefix=PATH. ๐๏ธPYTHONSAFEPATHโ if you set this to a non-empty string, Python will not automatically prepend a potentially unsafe path tosys.pathโ think the current directory, the script's directory, or an empty string. Basically: don't let sketchy paths sneak into your import search. See also the-Poption. ๐ก๏ธPYTHONSTARTUPโ if this points at the name of a readable file, the Python commands in that file get run before the first prompt shows up in interactive mode. And here's the cute part: it runs in the exact same namespace where your interactive commands run, so anything you define or import in there is just... available. No qualification needed. You can also use it to change the promptssys.ps1andsys.ps2. Main character setup fr. โจPYTHONTRACEMALLOCโ non-empty string? Then Python starts tracing memory allocations using thetracemallocmodule. The value itself is the maximum number of frames stored in a traceback of a trace. So like,PYTHONTRACEMALLOC=1keeps only the most recent frame. Small number, small stack pic. ๐ธPYTHONUNBUFFEREDโ set it to a non-empty string and it's the same as passing-u. That's it, that's the whole vibe. ๐PYTHONUSERBASEโ defines the user base directory. Python uses it to figure out the path of the usersite-packagesdirectory, plus the installation paths forpython -m pip install --user. ๐PYTHONUTF8โ set it to1and you turn on Python's "UTF-8 Mode". Set it to0and you turn it back off. On/off, that simple. ๐คPYTHONVERBOSEโ non-empty string โ same as-v. But if you set it to an integer, it's like passing-vthat many times. SoPYTHONVERBOSE=3is-v -v -v. Chatty icon. ๐ฃ๏ธPYTHONWARNDEFAULTENCODINGโ non-empty string โ Python raises anEncodingWarningwhenever the locale-specific default encoding gets used. A lil heads up before things get weird. โ ๏ธPYTHONWARNINGSโ a comma-separated string โ same as passing-Wonce for each separate value in the list. ๐จ
๐ Debug-mode variables ๐
important bestie: setting these only does anything in a debug build of Python โ meaning Python was configured with the --with-pydebug build option. Regular build? They're just sitting there, unbothered, doing nothing. ๐
PYTHONDUMPREFSโ set it and Python dumps all the objects and reference counts that are still alive after the interpreter shuts down. Spilling the tea on leaked refs. ๐ซPYTHONDUMPREFSFILEโ same idea, but it dumps those still-alive objects and reference counts into a file located under the path you give as the value of this variable. Now the tea's in writing. ๐PYTHON_PRESITEโ set this to a module and that module gets imported early in the interpreter lifecycle: before thesitemodule executes, and before the__main__module is even created. Only works on debug builds, as established. โจ
This one is equivalent to the -X presite=module option. ๐ช
๐ AUTHOR ๐
The Python Software Foundation: https://www.python.org/psf/
๐ INTERNET RESOURCES ๐
- 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. Wanna know the terms & conditions for accessing and otherwise using Python, plus a DISCLAIMER OF ALL WARRANTIES? Check the file "LICENSE" in the Python source distribution. Go read it, bestie, it's giving responsible. ๐ซถ
and that's the whole PYTHON(1) page, bestie ๐ the little footer at the bottom just said PYTHON(1) (y'know, the section 1 man page, which is where all the user commands live) โ so if you ever see that tag floating at the end of your man python, that's this page, telling you it's from the Python manual. Now go write something iconic with it. periodt. ๐
๐๐ฆ
๐ฆ where this page comes from
- alpine 3.24: python3-doc 3.14.10-r1 ยท PSF-2.0
- arch rolling: python 3.14.8-1
- arch rolling: python 3.14.9-1 ยท PSF-2.0
- fedora 43: python3 3.14.8-1.fc43 ยท Python-2.0.1
- fedora 43: python3 3.14.8-1.fc43 ยท Python-2.0.1
- fedora 44: python3 3.14.8-1.fc44 ยท Python-2.0.1
- fedora 44: python3 3.14.8-1.fc44 ยท Python-2.0.1
- nixos 26.05: python3 3.15.0
- nixpkgs unstable: python3-minimal 3.14.8
- ๐ girlified by deepseek-ai/DeepSeek-V4.1-Flash on : a language model's rewrite of the original, under its terms