python_environment_variables

Python Environment Variables

Python Environment Variables

Environment (a.k.a. shell) variables are systemwide settings that span programs and are used for global configuration.

Operational Variables

The following are major user-configurable environment variables related to script behavior:

PYTHONPATH

Augments the default search path for imported module files. The format of this variable’s value is the same as the shell’s PATH setting: directory pathnames separated by colons (semicolons on Windows). If set, module imports search for imported files or directories in each directory listed in PYTHONPATH, from left to right. Merged into sys.path — the full module search path for leftmost components in absolute imports — after the script’s directory, and before standard library directories. See also sys.path in The sys Module, and The import Statement.

PYTHONSTARTUP

If set to the name of a readable file, the Python commands in that file are executed before the first prompt is displayed in interactive mode (useful to define often-used tools).

PYTHONHOME

If set, the value is used as an alternate prefix directory for library modules (or sys.prefix, sys.exec_prefix). The default module search path uses sys.prefix/lib.

PYTHONCASEOK

If set, filename case is ignored in import statements (currently only on Windows and OS X).

PYTHONIOENCODING

Assign to string encodingname[:errorhandler] to override the default Unicode encoding (and optional error handler) used for text transfers made to the stdin, stdout, and stderr streams. This setting may be required for non-ASCII text in some shells (e.g., try setting this to utf8 or other if prints fail).

PYTHONHASHSEED

If set to “random”, a random value is used to seed the hashes of str, bytes, and datetime objects; may also be set to an integer in the range 0…4,294,967,295 to get hash values with a predictable seed (as of Python 3.2.3 and 2.6.8).

PYTHONFAULTHANDLER

If set, Python registers handlers at startup to dump a traceback on fatal signal errors (as of Python 3.3, and equivalent to -X faulthandler).

Python Command Option Variables

The following environment variables are synonymous with some of Python’s command-line options (see Python Command Options):

PYTHONDEBUG

If nonempty, same as -d option.

PYTHONDONTWRITEBYTECODE

If nonempty, same as -B option.

PYTHONINSPECT

If nonempty, same as -i option.

PYTHONNOUSERSITE

If nonempty, same as -s option.

PYTHONOPTIMIZE

If nonempty, same as -O option.

PYTHONUNBUFFERED

If nonempty, same as -u option.

PYTHONVERBOSE

If nonempty, same as -v option.

PYTHONWARNINGS

If nonempty, same as -W option, with same value. Also accepts a comma-separated string as equivalent to multiple -W options. (As of Python 3.2 and 2.7.)

python_environment_variables.txt · Last modified: 2024/04/28 03:21 (external edit)