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
。
應改用帶有
PyConfig
的Py_InitializeFromConfig()
API。全域配置變數:
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()
)
應改用帶有
PyConfig
的Py_InitializeFromConfig()
API 來設定這些選項。或者也可以使用PyConfig_Get()
在執行時取得這些選項。