ImportError: FloatProgress not found. Please update jupyter and ipywidgets.問題


一、問題描述:

在進行深度學習導包時,運行代碼:

import torch
import torchvision
import torchvision.transforms as transforms
import matplotlib.pyplot as plt
import sys
sys.path.append("..")
import d2lzh_pytorch as d2l

出現了“ImportError: FloatProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html” 錯誤。錯誤代碼如下:

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
---------------------------------------------------------------------------
NameError                                 Traceback (most recent call last)
D:\InstallSoftware\Anaconda\envs\spyder_py3.5\lib\site-packages\tqdm\notebook.py in status_printer(_, total, desc, ncols)
     97             else:  # No total? Show info style bar with no progress tqdm status
---> 98                 pbar = IProgress(min=0, max=1)
     99                 pbar.value = 1

NameError: name 'IProgress' is not defined

During handling of the above exception, another exception occurred:

ImportError                               Traceback (most recent call last)
<ipython-input-1-e1dda4d0e124> in <module>
      5 import sys
      6 sys.path.append("..")
----> 7 import d2lzh_pytorch as d2l

D:\InstallSoftware\Anaconda\envs\spyder_py3.5\d2lzh_pytorch\__init__.py in <module>
----> 1 from .utils import *
      2 

D:\InstallSoftware\Anaconda\envs\spyder_py3.5\d2lzh_pytorch\utils.py in <module>
      6 import d2lzh_pytorch as d2l
      7 
----> 8 minst_train = torchvision.datasets.FashionMNIST(root = '~/Datasets/FashionMNIST',train=True,download=True,transform=transforms.ToTensor())
      9 minst_test = torchvision.datasets.FashionMNIST(root = '~/Datasets/FashionMNIST',train=False,download=True,transform=transforms.ToTensor())
     10 print(type(mnist_train))

D:\InstallSoftware\Anaconda\envs\spyder_py3.5\lib\site-packages\torchvision\datasets\mnist.py in __init__(self, root, train, transform, target_transform, download)
     68 
     69         if download:
---> 70             self.download()
     71 
     72         if not self._check_exists():

D:\InstallSoftware\Anaconda\envs\spyder_py3.5\lib\site-packages\torchvision\datasets\mnist.py in download(self)
    135         for url, md5 in self.resources:
    136             filename = url.rpartition('/')[2]
--> 137             download_and_extract_archive(url, download_root=self.raw_folder, filename=filename, md5=md5)
    138 
    139         # process and save as torch files

D:\InstallSoftware\Anaconda\envs\spyder_py3.5\lib\site-packages\torchvision\datasets\utils.py in download_and_extract_archive(url, download_root, extract_root, filename, md5, remove_finished)
    262         filename = os.path.basename(url)
    263 
--> 264     download_url(url, download_root, filename, md5)
    265 
    266     archive = os.path.join(download_root, filename)

D:\InstallSoftware\Anaconda\envs\spyder_py3.5\lib\site-packages\torchvision\datasets\utils.py in download_url(url, root, filename, md5)
     83             urllib.request.urlretrieve(
     84                 url, fpath,
---> 85                 reporthook=gen_bar_updater()
     86             )
     87         except (urllib.error.URLError, IOError) as e:

D:\InstallSoftware\Anaconda\envs\spyder_py3.5\lib\site-packages\torchvision\datasets\utils.py in gen_bar_updater()
     13 
     14 def gen_bar_updater():
---> 15     pbar = tqdm(total=None)
     16 
     17     def bar_update(count, block_size, total_size):

D:\InstallSoftware\Anaconda\envs\spyder_py3.5\lib\site-packages\tqdm\notebook.py in __init__(self, *args, **kwargs)
    207         total = self.total * unit_scale if self.total else self.total
    208         self.container = self.status_printer(
--> 209             self.fp, total, self.desc, self.ncols)
    210         self.sp = self.display
    211 

D:\InstallSoftware\Anaconda\envs\spyder_py3.5\lib\site-packages\tqdm\notebook.py in status_printer(_, total, desc, ncols)
    102             # #187 #451 #558
    103             raise ImportError(
--> 104                 "FloatProgress not found. Please update jupyter and ipywidgets."
    105                 " See https://ipywidgets.readthedocs.io/en/stable"
    106                 "/user_install.html")

ImportError: FloatProgress not found. Please update jupyter and ipywidgets. See https://ipywidgets.readthedocs.io/en/stable/user_install.html

二、問題分析:

閱讀上面即可知,大多是因為ipywidgets原因:版本或者根本沒有安裝ipywidgets插件。

三、問題解決:

安裝ipywidgets插件官方文檔(這個解釋的全面)

1. pip安裝命令

建議使用pip命令安裝,使用conda安裝我出現了一系列奇奇怪怪的問題,同時個人建議安裝5.0.0版本pip install ipywidgets==5.0.0,避免在jupyter notebook中出現找不到ipywidgets插件的問題。

pip install ipywidgets
jupyter nbextension enable --py widgetsnbextension

2. conda 安裝命令

在多個環境中安裝
有時Jupyter Notebook和IPython內核安裝在不同的環境(virtualenv或conda環境)中。當使用環境提供不同的IPython內核時會發生這種情況。在這種情況下,安裝需要兩個步驟。

首先,您需要widgetsnbextension在包含Jupyter Notebook服務器的環境中安裝軟件包。接下來,您需要ipywidgets在將使用ipywidgets的每個內核環境中進行安裝 。

如果使用conda環境,並且筆記本計算機安裝在 base環境中,內核安裝在環境中py36,則命令為:

conda install -n base -c conda-forge widgetsnbextension
conda install -n py36 -c conda-forge ipywidgets

如果你使用conda 安裝出現了“關於ipywidgets插件,錯誤'Widget Javascript not detected. It may not be installed or enabled properly.'”這個問題參考博客:關於ipywidgets插件,錯誤'Widget Javascript not detected. It may not be installed or enabled properly.


免責聲明!

本站轉載的文章為個人學習借鑒使用,本站對版權不負任何法律責任。如果侵犯了您的隱私權益,請聯系本站郵箱yoyou2525@163.com刪除。



 
粵ICP備18138465號   © 2018-2025 CODEPRJ.COM