一、問題描述:
安裝ipywidgets后,我在運行下述代碼時,出現了錯誤``
import torch
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import ipywidgets as widgets
import sys
sys.path.append("..")
import d2lzh_pytorch as d2l
錯誤顯示:
Downloading http://fashion-mnist.s3-website.eu-central-1.amazonaws.com/train-images-idx3-ubyte.gz to C:\Users\木子/Datasets/FashionMNIST\FashionMNIST\raw\train-images-idx3-ubyte.gz
Widget Javascript not detected. It may not be installed or enabled properly.
A Jupyter widget could not be displayed because the widget state could not be found. This could happen if the kernel storing the widget is no longer available, or if the widget state was not saved in the notebook. You may be able to create the widget by running the appropriate cells.
錯誤截圖:
二、問題分析:
可以用命令pip search widgetsnbextension
檢查是否能在后台找到這個插件,如果不能就需要重新安裝。可以嘗試下面這個解決方法:
然而上面的運行我並沒有解決,於是進行了后續步驟。我安裝的版本是4.x,查看了一系列解決方案,大概指這個4.X版本在jupyter notebook中工作,會有一些不支持。安裝5.0.0版本,就可以解決這個版本存在“找不到
插件的問題”。於是我又重新安裝5.0.0版本。(詳看第三點)
三、問題解決:
1. 我首先使用命令pip install ipywidgets==5.0.0
(失敗,因為我已經安裝了4.x版本,無法下載。)
錯誤代碼:
Installing collected packages: ipywidgets
Found existing installation: ipywidgets 6.0.0
ERROR: Cannot uninstall 'ipywidgets'. It is a distutils installed project and thus we cannot accurately determine which files belong to it which would lead to only a partial uninstall.
錯誤截圖:
這個是anaconda的保護機制,顯示:這是一個distutils的安裝項目,因此,我們無法准確判斷哪些文件屬於它,這將導致只有部分卸載。,防止環境打亂。在卸載時,這種錯誤比較常見,實在想卸載,也可通過修改第三方文件夾的權限。(參考其他博文)
2. 命令:(依舊失敗)
pip install --ignore-installed --upgrade ipywidgets==5.0.0 -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
這個命令--ignore-installed
可以忽略已經安裝的版本,安裝特定版本。后面為了網速快,特地加了阿里雲的鏡像。
錯誤代碼:
Installing collected packages: attrs, setuptools, zipp, importlib-metadata, six, pyrsistent, jsonschema, ipython-genutils, pywin32, decorator, traitlets, jupyter-core, nbformat, Send2Trash, tornado, prometheus-client, MarkupSafe, jinja2, pywinpty, terminado, pyzmq, python-dateutil, jupyter-client, pickleshare, colorama, parso, jedi, pygments, backcall, wcwidth, prompt-toolkit, ipython, ipykernel, webencodings, bleach, entrypoints, testpath, defusedxml, mistune, pandocfilters, nbconvert, notebook, widgetsnbextension, ipywidgets
ERROR: Could not install packages due to an EnvironmentError: [WinError 5] 拒絕訪問。: 'd:\\installsoftware\\anaconda\\envs\\spyder_py3.5\\Lib\\site-packages\\win32\\win32api.pyd'
Consider using the `--user` option or check the permissions.
錯誤截圖:
大意是拒絕訪問,由於環境錯誤無法安裝包。同時給出了解決辦法加上
--user
。
3. 安裝命令(ipywidgets 5.0.0版本安裝成功)
pip install --ignore-installed --upgrade ipywidgets==5.0.0 --user -i http://mirrors.aliyun.com/pypi/simple/ --trusted-host mirrors.aliyun.com
截圖:
這里面有很多警告,但是還好啦,終於安裝成功了。到此,這個插件找尋不到的問題得到解決。
GitHub討論區參考:https://github.com/jupyter/notebook/issues/1386