计划在 Python 3.15 中移除¶
PyImport_ImportModuleNoBlock(): 改用PyImport_ImportModule()。PyWeakref_GetObject()和PyWeakref_GET_OBJECT(): 改用PyWeakref_GetRef()。 在 Python 3.12 及更旧的版本中可以使用 pythoncapi-compat 项目 来获取PyWeakref_GetRef()。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环境变量。
在 Python 3.13 和更旧的版本中可以使用 pythoncapi-compat 项目 来获取
PyConfig_Get().