ImportError: The _plotly_future_ module must be imported before the plotly module

ImportError: The _plotly_future_ module must be imported before the plotly module

我尝试在 Python 中重现制作 plotly 情节的示例,该情节作为第一个示例 here: "Subplots in Python" 发布。我在 Jupyter notebook 上工作,plotly 版本:3.10.0,Python 版本:3.6.3.

在运行那个例子之后:

from plotly.subplots import make_subplots
import plotly.graph_objs as go
from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot

## Allow to generate plotly plots inline in notebook
init_notebook_mode(connected=True)

fig = make_subplots(rows=1, cols=2)
fig.add_trace(go.Scatter(x=[1, 2, 3], y=[4, 5, 6]), row=1, col=1)
fig.add_trace(go.Scatter(x=[20, 30, 40], y=[50, 60, 70]), row=1, col=2)
fig.update_layout(height=600, width=800, title_text="Subplots")
iplot(fig)

我得到 ValueError:

ValueError: 
plotly.subplots.make_subplots may only be used in the
v4_subplots _plotly_future_ mode.  To try it out, run
>>> from _plotly_future_ import v4_subplots
before importing plotly.

然后我在导入的最顶部添加了 from _plotly_future_ import v4_subplots。我清理了输出,使用 %restet 清理了所有变量,甚至刷新了笔记本,但是带有标题的代码:

from _plotly_future_ import v4_subplots 
from plotly.subplots import make_subplots 
import plotly.graph_objs as go from plotly.offline import download_plotlyjs, 
init_notebook_mode, plot, iplot
# (...)

结果现在在 ImportError:

---------------------------------------------------------------------------
ImportError                               Traceback (most recent call last)
<ipython-input-14-d2ad52c99588> in <module>
----> 1 from _plotly_future_ import v4_subplots
      2 from plotly.subplots import make_subplots
      3 import plotly.graph_objs as go
      4 from plotly.offline import download_plotlyjs, init_notebook_mode, plot, iplot
      5 

c:\users\karasma6\appdata\local\continuum\anaconda3\envs\actigrapy\lib\site-packages\_plotly_future_\v4_subplots.py in <module>
      2 from _plotly_future_ import _future_flags, _assert_plotly_not_imported
      3 
----> 4 _assert_plotly_not_imported()
      5 _future_flags.add('v4_subplots')

c:\users\karasma6\appdata\local\continuum\anaconda3\envs\actigrapy\lib\site-packages\_plotly_future_\__init__.py in _assert_plotly_not_imported()
      9     if 'plotly' in sys.modules:
     10         raise ImportError("""\
---> 11 The _plotly_future_ module must be imported before the plotly module""")
     12 
     13 

ImportError: The _plotly_future_ module must be imported before the plotly module

如何解决?

您可能需要重新启动内核:仅刷新笔记本是不够的。

也就是说,第 4 版现已发布,所以您最好的选择是升级 :)