Interpreter initialization and finalization¶
See Python Initialization Configuration for details on how to configure the interpreter prior to initialization.
Before Python initialization¶
In an application embedding Python, the Py_Initialize() function must
be called before using any other Python/C API functions; with the exception of
a few functions and the global configuration variables.
The following functions can be safely called before Python is initialized:
Functions that initialize the interpreter:
the runtime pre-initialization functions covered in Python Initialization Configuration
Configuration functions:
PyInitFrozenExtensions()the configuration functions covered in Python Initialization Configuration
Informative functions:
Utilities:
the status reporting and utility functions covered in Python Initialization Configuration
Memory allocators:
Synchronization:
Note
Despite their apparent similarity to some of the functions listed above,
the following functions should not be called before the interpreter has
been initialized: Py_EncodeLocale(), PyEval_InitThreads(), and
Py_RunMain().
Global configuration variables¶
Python has variables for the global configuration to control different features and options. By default, these flags are controlled by command line options.
When a flag is set by an option, the value of the flag is the number of times
that the option was set. For example, -b sets Py_BytesWarningFlag
to 1 and -bb sets Py_BytesWarningFlag to 2.
-
int Py_BytesWarningFlag¶
This API is kept for backward compatibility: setting
PyConfig.bytes_warningshould be used instead, see Python Initialization Configuration.Issue a warning when comparing
bytesorbytearraywithstrorbyteswithint. Issue an error if greater or equal to2.Set by the
-boption.Deprecated since version 3.12, will be removed in version 3.15.
-
int Py_DebugFlag¶
This API is kept for backward compatibility: setting
PyConfig.parser_debugshould be used instead, see Python Initialization Configuration.Turn on parser debugging output (for expert only, depending on compilation options).
Set by the
-doption and thePYTHONDEBUGenvironment variable.Deprecated since version 3.12, will be removed in version 3.15.
-
int Py_DontWriteBytecodeFlag¶
This API is kept for backward compatibility: setting
PyConfig.write_bytecodeshould be used instead, see Python Initialization Configuration.If set to non-zero, Python won’t try to write
.pycfiles on the import of source modules.Set by the
-Boption and thePYTHONDONTWRITEBYTECODEenvironment variable.Deprecated since version 3.12, will be removed in version 3.15.
-
int Py_FrozenFlag¶
This API is kept for backward compatibility: setting
PyConfig.pathconfig_warningsshould be used instead, see Python Initialization Configuration.Private flag used by
_freeze_moduleandfrozenmainprograms.