python - ImportError: _plotly_future_ 模块必须在 plotly 模块之前导入
问题描述
我尝试重现在plotly
Python 中使用多个子图进行绘图的示例,该示例在此处作为第一个示例发布:“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 版现已推出,因此您最好的选择是升级 :)
推荐阅读
- r - 在 Rcpp 中使用 SEXP 迭代 R 对象
- html - 页脚涵盖博客内容
- plugins - 需要插件代码在实体中创建记录
- php - 升级到 Symfony flex (3.4) - 有很多捆绑包时的问题
- java - 如何导致矩阵形式的变化?
- php - 使用三元运算符简化条件表达式
- c++ - Pytorch 按元素应用各种功能(C++ API)
- node.js - 将带有 Content-Disposition 附件的 PNG 转换为 Nodejs 中的 Base64 或缓冲区
- django - DRF 中的观看次数增加
- netsuite - 如何在“新 nlobjSearchFilter”中添加 2 个条件?