运行IPyhon.widgets时没有名为"ipywidgets"的模块错误

Yas*_*eth 2 python ipython ipython-notebook

我安装了IPython 4.0.1.我无法弄清楚以下错误的原因 -

>>> from IPython.html import widgets
>>> k = widgets.Box
Traceback (most recent call last):
  File "C:\Python34\lib\site-packages\IPython\utils\shimmodule.py", line 90, in __getattr__
    return import_item(name)
  File "C:\Python34\lib\site-packages\IPython\utils\importstring.py", line 31, in import_item
    module = __import__(package, fromlist=[obj])
ImportError: No module named 'ipywidgets'

During handling of the above exception, another exception occurred:

Traceback (most recent call last):
  File "<pyshell#8>", line 1, in <module>
    k = widgets.Box
  File "C:\Python34\lib\site-packages\IPython\utils\shimmodule.py", line 92, in __getattr__
    raise AttributeError(key)
AttributeError: Box
Run Code Online (Sandbox Code Playgroud)

我怎样才能解决这个问题?

小智 9

在IPython 3和IPython 4之间,许多组件被分成不同的包(http://blog.jupyter.org/2015/04/15/the-big-split/).小部件是受影响的功能之一.

您可以通过标准渠道安装ipywidgets(正如Yashu Seth建议的那样):

pip install ipywidgets
# or
conda install ipywidgets
Run Code Online (Sandbox Code Playgroud)

你应该养成不从IPython.html导入小部件的习惯,因为旧的库结构已被弃用.


Yas*_*eth 5

ipywidgets 未随 IPython 一起安装。只需安装它即可。

pip install ipywidgets
Run Code Online (Sandbox Code Playgroud)