plotly / plotly/plotly.py

Circular Import Dependency in Plotly Templates

未关闭
#5,281 1 条评论 0 个 reaction 已指派 0 人 在 GitHub 查看

还没有人认领这个 Issue。

bug P1
主要语言
Python
星标
18.8k
派生
2.8k
平均合并
16 小时 26 分钟
30 天内合并 PR
21

描述

The issue is that plotly's template system has a circular import dependency:

  1. plotly.graph_objs.__init__.py imports all trace types including Heatmapgl
  2. During this import process, it also loads template data
  3. layout/template/data/_heatmapgl.py tries to import Heatmapgl from plotly.graph_objs
  4. But plotly.graph_objs is still in the process of being imported!

This occurred when attempting to use plotly and plotly-resampler and a heatmap.

Reproduction of Error

Minimal reproduction code:

import plotly.graph_objs as go
go.Heatmapgl()  # ✅ Success

# But this fails:
from plotly_resampler import FigureResampler
fig = FigureResampler(go.Figure())  # ❌ Circular import

Versions affected:

plotly==5.24.1
plotly-resampler==0.10.0

Work around

This can be worked around by forcing import order:

import plotly.graph_objs  # Force full initialization first
from plotly_resampler import FigureResampler  # Then import resampler

贡献指南

打开贡献指南

从这里开始

  1. 先读完整个 Issue,再读项目的贡献指南。
  2. 在 Issue 下留言说明你要接手 —— 这能避免两个人做同样的事。
  3. Fork 仓库,在一个分支上完成修改。
  4. 提交 Pull Request,并在描述里引用这个 Issue 编号。

调研方向

使用 plotly==5.24.1 和 plotly-resampler==0.10.0 重现该失败,然后检查 plotly.graph_objs.init.py 和 layout/template/data/_heatmapgl.py。根据报告的 FigureResampler 示例跟踪导入顺序。当该示例无需先手动导入 plotly.graph_objs 即可导入并构建图形时,即表示完成。

由索引模型根据 Issue 内容生成。

评估

技术栈
python
领域
data-visualization
Issue 类型
缺陷
难度
3/5
预计耗时
1-2 天
活跃度
停滞
描述清晰度
基本清楚
新手友好度
48/100

把新 issue 发到你的邮箱

精选适合新手参与的 GitHub issue 摘要。