计划在 Python 3.15 中移除¶
The
PyImport_ImportModuleNoBlock(): UsePyImport_ImportModule()instead.PyWeakref_GetObject()andPyWeakref_GET_OBJECT(): UsePyWeakref_GetRef()instead. The pythoncapi-compat project can be used to getPyWeakref_GetRef()on Python 3.12 and older.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 thePYTHONHOMEenvironment 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(): Clearsys.warnoptionsandwarnings.filtersinstead.
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_levelorPyConfig_Get("optimization_level")。Py_NoSiteFlag: 改用PyConfig.site_import或PyConfig_Get("site_import")。Py_BytesWarningFlag: 改用PyConfig.bytes_warningorPyConfig_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()在运行时获取这些选项。