计划在 Python 3.15 中移除¶
PyWeakref_GetObject()
和PyWeakref_GET_OBJECT()
:请改用PyWeakref_GetRef()
。 pythoncapi-compat 项目 可用于在 Python 3.12 及更早版本中获取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()
:请改用PyConfig_Get("module_search_paths")
(sys.path
)。Py_GetPrefix()
:请改用PyConfig_Get("base_prefix")
(sys.base_prefix
)。如果需要处理虚拟环境,请使用PyConfig_Get("prefix")
(sys.prefix
)。Py_GetExecPrefix()
:请改用PyConfig_Get("base_exec_prefix")
(sys.base_exec_prefix
)。如果需要处理虚拟环境,请使用PyConfig_Get("exec_prefix")
(sys.exec_prefix
)。Py_GetProgramFullPath()
:请改用PyConfig_Get("executable")
(sys.executable
)。Py_GetProgramName()
:请改用PyConfig_Get("executable")
(sys.executable
)。Py_GetPythonHome()
:请改用PyConfig_Get("home")
或PYTHONHOME
环境变量。
可以使用 pythoncapi-compat 项目 在 Python 3.13 及更早版本中获得
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
或PyConfig_Get("optimization_level")
。Py_NoSiteFlag
:请改用PyConfig.site_import
或PyConfig_Get("site_import")
。Py_BytesWarningFlag
:请改用PyConfig.bytes_warning
或PyConfig_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()
在运行时获取这些选项。