# info > python

yaml
---
type: CommandReference
command: python
mode: man
section: 1
source: man-pages
---

## Quick Reference

- `python script.py` — run a script
- `python -c 'print("hello")'` — execute a command
- `python -m module_name` — run a module as a script
- `python -i script.py` — run script then enter interactive mode
- `python -O script.py` — run with basic optimizations (remove assert, __debug__)
- `python -B script.py` — run without writing .pyc files
- `python -W ignore::DeprecationWarning` — suppress deprecation warnings
- `python -X dev script.py` — run with development mode (extra checks)

## Name

python - an interpreted, interactive, object-oriented programming language

## Synopsis

`python [ -B ] [ -b ] [ -d ] [ -E ] [ -h ] [ -i ] [ -I ] [ -m module-name ] [ -q ] [ -O ] [ -OO ] [ -s ] [ -S ] [ -u ] [ -v ] [ -V ] [ -W argument ] [ -x ] [ -X option ] [ -? ] [ --check-hash-based-pycs default | always | never ] [ -c command | script | - ] [ arguments ]`

## Description

Python is an interpreted, interactive, object-oriented programming language. When called with standard input connected to a tty, it prompts for commands and executes them until EOF. When called with a file name argument or with a file as standard input, it reads and executes a script from that file. When called with `-c command`, it executes the Python statement(s) given as command. The script name and additional arguments are passed in `sys.argv` (a list of strings). In interactive mode, the primary prompt is `>>>` and the secondary prompt is `...`. The interpreter quits on EOF at a prompt. Unhandled exceptions print a stack trace; in non-interactive mode the interpreter exits. The interrupt signal raises `KeyboardInterrupt`.

## Options

### General
- `-c command` — specify the command to execute; terminates option list
- `-h`, `-?`, `--help` — print usage and exit
- `-V`, `--version` — print Python version number and exit; twice for build info
- `-m module-name` — run module as script; terminates option list
- `-?` — same as `-h`

### Execution
- `-i` — enter interactive mode after executing script or `-c` command; do not read `$PYTHONSTARTUP`
- `-I` — isolated mode (implies `-E` and `-s`); ignores `PYTHON*` env vars, restricts `sys.path`
- `-s` — don't add user site directory to `sys.path`
- `-S` — disable import of the `site` module and site-dependent `sys.path` manipulations
- `-u` — force stdout and stderr to be unbuffered (no effect on stdin)
- `-x` — skip the first line of source (DOS hack); line numbers in errors will be off by one
- `-q` — do not print version and copyright messages (also suppressed in non-interactive mode)

### Optimization and bytecode
- `-O` — remove assert statements and `__debug__` conditionals; add `.opt-1` to `.pyc` filename
- `-OO` — do `-O` and also discard docstrings; add `.opt-2` to `.pyc` filename
- `-B` — don't write `.pyc` files on import (see also `PYTHONDONTWRITEBYTECODE`)
- `--check-hash-based-pycs mode` — control how hash-based `.pyc` files are checked (`default`, `always`, `never`)

### Warning control
- `-b` — issue warnings about `str(bytes_instance)`, `str(bytearray_instance)`, and comparing bytes/bytearray with str; `-bb` issues errors
- `-W argument` — warning control. Argument can be:
  - `-Wdefault`, `-Werror`, `-Walways`, `-Wmodule`, `-Wonce`, `-Wignore`
  - Full form: `action:message:category:module:lineno`
  - Multiple `-W` options can be given; last matching action wins. Invalid `-W` options are ignored.

### Debugging and diagnostics
- `-d` — parser debugging output (expert only, depends on compilation)
- `-v` — print message each time a module is initialized; twice for file checks and module cleanup info
- `-X option` — set implementation-specific option:
  - `-X faulthandler` — enable faulthandler
  - `-X showrefcount` — output total reference count and memory blocks (debug builds only)
  - `-X tracemalloc[=NFRAME]` — start tracing Python memory allocations
  - `-X importtime` — show how long each import takes
  - `-X dev` — enable CPython development mode (adds runtime checks, debug hooks, asyncio debug, etc.)
  - `-X utf8[=0]` — enable UTF-8 mode for OS interfaces; `-X utf8=0` disables
  - `-X pycache_prefix=PATH` — write `.pyc` files to a parallel tree
  - `-X warn_default_encoding` — enable `EncodingWarning` for `encoding=None`
  - `-X int_max_str_digits=number` — limit size of int<->str conversions (default: `sys.int_info.default_max_str_digits`)
- `-E` — ignore environment variables `PYTHONPATH`, `PYTHONHOME`, etc.

## Environment Variables

- `PYTHONHOME` — change location of standard Python libraries (default: `{prefix}/lib/python<version>`)
- `PYTHONPATH` — augment default search path for module files (colon-separated directories)
- `PYTHONPLATLIBDIR` — override `sys.platlibdir`
- `PYTHONSTARTUP` — execute commands from this file before first prompt in interactive mode
- `PYTHONOPTIMIZE` — equivalent to `-O` (non-empty string) or `-O` multiple times (integer)
- `PYTHONDEBUG` — equivalent to `-d` (non-empty string) or multiple `-d` (integer)
- `PYTHONDONTWRITEBYTECODE` — equivalent to `-B` (non-empty string)
- `PYTHONINSPECT` — equivalent to `-i` (non-empty string)
- `PYTHONIOENCODING` — override encoding for stdin/stdout/stderr (format: `encoding:errorhandler`; stderr always uses `backslashreplace`)
- `PYTHONNOUSERSITE` — equivalent to `-s` (non-empty string)
- `PYTHONUNBUFFERED` — equivalent to `-u` (non-empty string)
- `PYTHONVERBOSE` — equivalent to `-v` (non-empty string) or multiple `-v` (integer)
- `PYTHONWARNINGS` — comma-separated string, equivalent to multiple `-W` options
- `PYTHONHASHSEED` — set to `"random"` for random seed, or an integer in `[0, 4294967295]` for fixed seed (0 disables hash randomization)
- `PYTHONINTMAXSTRDIGITS` — limit maximum digit characters in int<->str conversions (0 disables limit; bases 2,4,8,16,32 never limited)
- `PYTHONMALLOC` — set memory allocator (`malloc`, `pymalloc`) and debug hooks (`debug`, `malloc_debug`, `pymalloc_debug`)
- `PYTHONMALLOCSTATS` — print pymalloc statistics on arena creation and shutdown (ignored if `PYTHONMALLOC` forces C malloc or no pymalloc)
- `PYTHONASYNCIODEBUG` — enable asyncio debug mode (non-empty string)
- `PYTHONTRACEMALLOC` — start tracing memory allocations with tracemalloc; value is max frames in traceback
- `PYTHONFAULTHANDLER` — call `faulthandler.enable()` at startup (equivalent to `-X faulthandler`)
- `PYTHONEXECUTABLE` — override `sys.argv[0]` (Mac OS X only)
- `PYTHONUSERBASE` — define user base directory for site-packages and Distutils install paths
- `PYTHONPROFILEIMPORTTIME` — show import times (equivalent to `-X importtime`)
- `PYTHONBREAKPOINT` — set to `0` to disable default debugger, or set to a callable

**Debug-build only:**
- `PYTHONTHREADDEBUG` — print threading debug info (deprecated in 3.10, removed in 3.12)
- `PYTHONDUMPREFS` — dump objects and reference counts after shutdown

## Files and Directories

- `${exec_prefix}/bin/python` — recommended location of the interpreter
- `${prefix}/lib/python<version>`, `${exec_prefix}/lib/python<version>` — standard modules
- `${prefix}/include/python<version>`, `${exec_prefix}/include/python<version>` — include files for developing extensions / embedding

On Debian GNU/{Hurd,Linux}, default for both `${prefix}` and `${exec_prefix}` is `/usr`.

## See Also

- `pydoc` — documentation viewer for Python modules and packages

## 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. See the file "LICENSE" in the Python source distribution for terms and conditions and a disclaimer of all warranties.