计划在 Python 3.15 中移除¶
The
PyImport_ImportModuleNoBlock()
: UsePyImport_ImportModule()
instead.PyWeakref_GetObject()
和PyWeakref_GET_OBJECT()
: 改用PyWeakref_GetRef()
。 在 Python 3.12 及更旧的版本中可以使用 pythoncapi-compat 项目 来获取PyWeakref_GetRef()
。Py_UNICODE
类型和Py_UNICODE_WIDE
宏:改用wchar_t
。PyUnicode_AsDecodedObject()
: 改用PyCodec_Decode()
。PyUnicode_AsDecodedUnicode()
: 改用PyCodec_Decode()
;请注意某些编解码器 (例如 "base64") 可能返回str
以外的类型,比如bytes
。PyUnicode_AsEncodedObject()
: 改用PyCodec_Encode()
。PyUnicode_AsEncodedUnicode()
: 使用PyCodec_Encode()
代替;请注意,某些编解码器(如 "base64")可能返回bytes
之外的类型,如str
。Python 初始化函数, Python 3.13 中弃用:
Py_GetPath()
: UsePyConfig_Get("module_search_paths")
(sys.path
) instead.Py_GetPrefix()
: UsePyConfig_Get("base_prefix")
(sys.base_prefix
) instead. UsePyConfig_Get("prefix")
(sys.prefix
) if virtual environments need to be handled.Py_GetExecPrefix()
: UsePyConfig_Get("base_exec_prefix")
(sys.base_exec_prefix
) instead. UsePyConfig_Get("exec_prefix")
(sys.exec_prefix
) if virtual environments need to be handled.Py_GetProgramFullPath()
: UsePyConfig_Get("executable")
(sys.executable
) instead.Py_GetProgramName()
: UsePyConfig_Get("executable")
(sys.executable
) instead.Py_GetPythonHome()
: UsePyConfig_Get("home")
or thePYTHONHOME
environment variable instead.
在 Python 3.13 和更旧的版本中可以使用 pythoncapi-compat 项目 来获取
PyConfig_Get()
。用于配置 Python 的初始化的函数,在 Python 3.11 中已弃用:
PySys_SetArgvEx()
: 改为设置PyConfig.argv
。PySys_SetArgv()
: 改为设置PyConfig.argv
。Py_SetProgramName()
: 改为设置PyConfig.program_name
。Py_SetPythonHome()
: 改为设置PyConfig.home
。PySys_ResetWarnOptions()
: 改为清除sys.warnoptions
和warnings.filters
。
Py_InitializeFromConfig()
API 应与PyConfig
一起使用。全局配置变量:
Py_DebugFlag
: 改用PyConfig.parser_debug
或PyConfig_Get("parser_debug")
。Py_VerboseFlag
: 改用PyConfig.verbose
或PyConfig_Get("verbose")
。Py_InteractiveFlag
: 改用PyConfig.interactive
或PyConfig_Get("interactive")
。Py_InspectFlag
: 改用PyConfig.inspect
或PyConfig_Get("inspect")
。Py_OptimizeFlag
: 改用PyConfig.optimization_level
orPyConfig_Get("optimization_level")
。Py_NoSiteFlag
: 改用PyConfig.site_import
或PyConfig_Get("site_import")
。Py_BytesWarningFlag
: 改用PyConfig.bytes_warning
orPyConfig_Get("bytes_warning")
。Py_FrozenFlag
: 改用PyConfig.pathconfig_warnings
或PyConfig_Get("pathconfig_warnings")
。Py_IgnoreEnvironmentFlag
: 改用PyConfig.use_environment
或PyConfig_Get("use_environment")
。Py_DontWriteBytecodeFlag
: 改用PyConfig.write_bytecode
或PyConfig_Get("write_bytecode")
。Py_NoUserSiteDirectory
: 使用PyConfig.user_site_directory
或PyConfig_Get("user_site_directory")
代替。Py_UnbufferedStdioFlag
: 改用PyConfig.buffered_stdio
或PyConfig_Get("buffered_stdio")
。Py_HashRandomizationFlag
: 改用PyConfig.use_hash_seed
和PyConfig.hash_seed
或PyConfig_Get("hash_seed")
。Py_IsolatedFlag
: 改用PyConfig.isolated
或PyConfig_Get("isolated")
。Py_LegacyWindowsFSEncodingFlag
: 改用PyPreConfig.legacy_windows_fs_encoding
或PyConfig_Get("legacy_windows_fs_encoding")
。Py_LegacyWindowsStdioFlag
: 改用PyConfig.legacy_windows_stdio
或PyConfig_Get("legacy_windows_stdio")
。Py_FileSystemDefaultEncoding
,Py_HasFileSystemDefaultEncoding
: 改用PyConfig.filesystem_encoding
或PyConfig_Get("filesystem_encoding")
。Py_FileSystemDefaultEncodeErrors
: 改用PyConfig.filesystem_errors
或PyConfig_Get("filesystem_errors")
。Py_UTF8Mode
: 改用PyPreConfig.utf8_mode
或PyConfig_Get("utf8_mode")
。 (参见Py_PreInitialize()
)
Py_InitializeFromConfig()
API 应与PyConfig
一起使用,以设置这些选项。 或者使用PyConfig_Get()
在运行时获取这些选项。