ImportError:`iplot`只能在IPython Notebook中运行

时间:2018-12-30 15:32:41

标签: python pycharm ipython chainer

当我在Mac上的PyCharm中运行以下代码时:

import numpy as np 
import pandas as pd 

from subprocess import check_output
print(check_output(["ls", "../input"]).decode("utf8"))


import time
import copy
import numpy as np
import pandas as pd
import chainer
import chainer.functions as F
import chainer.links as L
from plotly import tools
from plotly.graph_objs import *
from plotly.offline import init_notebook_mode, iplot, iplot_mpl
init_notebook_mode()
data = pd.read_csv('../input/Data/Stocks/goog.us.txt')
data['Date'] = pd.to_datetime(data['Date'])
data = data.set_index('Date')
print(data.index.min(), data.index.max())
data.head()

有一些错误:

UserWarning: Accelerate has been detected as a NumPy backend library.
vecLib, which is a part of Accelerate, is known not to work correctly with Chainer.
We recommend using other BLAS libraries such as OpenBLAS.
For details of the issue, please see
https://docs.chainer.org/en/stable/tips.html#mnist-example-does-not-converge-in-cpu-mode-on-mac-os-x.

Please be aware that Mac OS X is not an officially supported OS.

  ''')  # NOQA
Traceback (most recent call last):
  File "/Users/yindeyong/Desktop/PythonProjects/pythonstock/DQNStcok.py", line 33, in <module>
    init_notebook_mode()
  File "/Users/yindeyong/Desktop/PythonProjects/envs/stockenv/lib/python3.6/site-packages/plotly/offline/offline.py", line 250, in init_notebook_mode
    raise ImportError('`iplot` can only run inside an IPython Notebook.')
ImportError: `iplot` can only run inside an IPython Notebook.

Process finished with exit code 1

我是Chainer和DQN的新手。有人可以帮我编辑此代码以使其正常工作吗?非常感谢!

2 个答案:

答案 0 :(得分:4)

似乎您正在尝试在普通的Python代码(即不是IPython Notebook)中运行绘图交互功能(i前缀)。 iplot提供了一个交互式图表,您可以在笔记本中进行游戏。

我将从删除iplot导入并将其替换为普通的plot开始。另外,从导入中删除iplot_mplinit_notebook_mode

答案 1 :(得分:0)

您可以在虚拟环境中安装'ipython',然后尝试直接从终端运行它。

  • 激活虚拟环境
  • pip3安装ipython
  • python3 prog.py

以我的情况工作。