You need to enable JavaScript to run this app.
优惠活动
大模型
产品
解决方案
定价
更多

使用emnist的list_datasets()时触发BadZipFile错误求助

解决EMNIST库list_datasets()的BadZipFile错误

问题根源:之前下载536MB数据集时网络中断,导致本地缓存的zip文件损坏。卸载重装EMNIST库没用,因为库本身不包含数据集,缓存文件存在本地独立目录里,卸载操作不会删除它。

解决步骤:

  • 第一步:定位损坏的缓存文件路径
    运行这段代码直接打印缓存文件的具体位置:
    import emnist
    print(emnist.get_cached_data_path())
    
  • 第二步:删除损坏的zip文件
    根据打印的路径找到对应的文件(通常命名类似emnist.zip),直接删除即可。
    如果不想写代码,也可以手动查找常见缓存位置:
    • Windows系统:C:\Users\[你的用户名]\.cache\emnist
    • Linux/macOS系统:~/.cache/emnist
  • 第三步:重新调用list_datasets()
    现在函数会重新完整下载数据集,确保这次网络稳定,避免中途中断。

错误栈信息:

BadZipFile                                Traceback (most recent call last)
Cell In [3], line 2
      1 #Download dataset and it is 536 MB
----> 2 list_datasets()

File ~\AppData\Local\Programs\Python\Python311\Lib\site-packages\emnist\__init__.py:223, in list_datasets()
    221 cache_path = get_cached_data_path()
    222 results = []
--> 223 with zipfile.ZipFile(cache_path) as zf:
    224     for path in zf.namelist():
    225         match = DATASET_ZIP_PATH_REGEX.fullmatch(path)

File ~\AppData\Local\Programs\Python\Python311\Lib\zipfile.py:1299, in ZipFile.__init__(self, file, mode, compression, allowZip64, compresslevel, strict_timestamps, metadata_encoding)
   1297 try:
   1298     if mode == 'r':
--> 1299         self._RealGetContents()
   1300     elif mode in ('w', 'x'):
   1301         # set the modified flag so central directory gets written
   1302         # even if no files are added to the archive
   1303         self._didModify = True

File ~\AppData\Local\Programs\Python\Python311\Lib\zipfile.py:1366, in ZipFile._RealGetContents(self)
   1364     raise BadZipFile("File is not a zip file")
   1365 if not endrec:
--> 1366     raise BadZipFile("File is not a zip file")
   1367 if self.debug > 1:
   1368     print(endrec)

BadZipFile: File is not a zip file

内容的提问来源于stack exchange,提问作者Pramiti Sirothia

相关产品推荐
方舟 Agent Plan

超全模态模型 × Harness 升级,最新支持 Deepseek-V4.1-Flash、GLM-5.3 系列、Doubao-Seedream-5.0-pro、Kimi-K3 (部分), 限时 9.9 元起

最近更新时间:2026.07.13 00:05:53