You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

Flask-GraphQL导入报错无法导入get_default_backend该如何解决

错误原因

你遇到的是依赖包版本不兼容问题:graphql-core 3.x版本移除了旧版本的get_default_backendAPI,而你安装的graphql-server-core 1.1.1和Flask-GraphQL 2.0.0仅适配graphql 2.x版本栈,和你当前安装的graphene 3.0、graphql-core 3.x系列版本不匹配,所以触发导入报错。

解决方案

方案1:降级到兼容的版本组合

如果你要继续使用Flask-GraphQL 2.x,可以直接安装以下经过验证的兼容版本栈,执行命令:

pip install Flask-GraphQL==2.0.1 graphene==2.1.9 graphql-core==2.3.2 graphql-relay==2.0.1 graphql-server-core==1.2.0

安装完成后再执行import flask_graphql即可正常运行。

方案2:使用适配3.x版本的替代依赖

Flask-GraphQL已经停止维护,如果你需要使用graphene 3.x版本栈,可以用官方维护的graphene-flask替代:

  • 先卸载旧的Flask-GraphQL:pip uninstall -y Flask-GraphQL
  • 安装新的适配包:pip install graphene-flask
  • 代码中导入语句替换为:from graphene_flask import GraphQL

内容的提问来源于stack exchange,提问作者orome

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.09.24 10:15:08