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

导入Hugging Face的datasets包时触发PyArrow属性错误求助

问题

尝试使用多个不同Python版本(3.9.6、3.10、3.11.4、3.11.8)创建环境,并安装了不同版本的PyArrow,但均未解决datasets库导入时的AttributeError: readonly attribute错误。

报错详情:

AttributeError Traceback (most recent call last)
Cell In[1], line 1
----> 1 import datasets

File ~/anaconda3/envs/hugging_face/lib/python3.11/site-packages/datasets/init.py:34
28 if _version.parse(pyarrow.version).major < 1:
29 raise ImportWarning(
30 "To use datasets, the module pyarrow>=1.0.0 is required, and the current version of pyarrow doesn't match this condition.\n"
31 "If you are running this in a Google Colab, you should probably just restart the runtime to use the right version of pyarrow."
32 )
---> 34 from .arrow_dataset import Dataset, concatenate_datasets
35 from .arrow_reader import ArrowReader, ReadInstruction
36 from .arrow_writer import ArrowWriter

File ~/anaconda3/envs/hugging_face/lib/python3.11/site-packages/datasets/arrow_dataset.py:45
42 from datasets.tasks.text_classification import TextClassification
44 from . import config, utils
---> 45 from .arrow_reader import ArrowReader
46 from .arrow_writer import ArrowWriter, OptimizedTypedSequence
47 from .features import ClassLabel, Features, Value

File ~/anaconda3/envs/hugging_face/lib/python3.11/site-packages/datasets/arrow_reader.py:33
30 from datasets.utils.file_utils import DownloadConfig
32 from .naming import _split_re, filename_for_dataset_split
...
---> 61 wrapper.wrapped = wrapped
62 # Return the wrapper so this can be used as a decorator via partial()
63 return wrapper

AttributeError: readonly attribute

已多次重启环境,尝试多种PyArrow版本,问题仍未解决。

可能的根源及解决方法

  • datasets版本适配问题:部分旧版datasets在Python 3.11+环境下会触发装饰器修改只读属性的错误,建议安装datasets最新稳定版,或指定与当前Python版本匹配的版本(如Python 3.11对应datasets>=2.10.0)。
  • 依赖冲突:环境中其他库可能干扰了datasets的导入逻辑。创建全新的干净虚拟环境,仅通过pip install datasets安装,让pip自动匹配适配的PyArrow版本,避免手动指定版本导致的冲突。
  • 文件损坏或权限异常:虚拟环境安装过程中可能出现文件损坏,导致__wrapped__属性被标记为只读。删除当前环境后重新创建,或执行pip install --force-reinstall datasets pyarrow强制重装两个库,确保文件完整且权限正常。
  • 混合安装冲突:如果同时用conda和pip安装依赖,可能引发底层库兼容性问题。统一使用一种包管理工具安装所有依赖,避免混合安装。

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

相关产品推荐
方舟 Agent Plan

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

最近更新时间:2026.06.28 14:33:25