原创

bug解决:AttributeError: module ‘collections‘ has no attribute “*”

温馨提示:
本文最后更新于 2022年12月26日,已超过 482 天没有更新。若文章内的图片失效(无法正常加载),请留言反馈或直接联系我

背景

       做二代宏基因组数据拼接时,spades.py调用报错。

       具体报错如下:

Traceback (most recent call last):

  File "/share/home/xiehs/bin/spades.py", line 659, in <module>

    main(sys.argv)

  File "/share/home/xiehs/bin/spades.py", line 599, in main

    print_params(log, log_filename, command_line, args, cfg)

  File "/share/home/xiehs/bin/spades.py", line 327, in print_params

    print_used_values(cfg, log)

  File "/share/home/xiehs/bin/spades.py", line 117, in print_used_values

    dataset_data = pyyaml.load(open(cfg["dataset"].yaml_filename))

  File "/share/home/xiehs/biosoft/SPAdes-3.15.3-Linux/share/spades/pyyaml3/__init__.py", line 72, in load

    return loader.get_single_data()

  File "/share/home/xiehs/biosoft/SPAdes-3.15.3-Linux/share/spades/pyyaml3/constructor.py", line 37, in get_single_data

    return self.construct_document(node)

  File "/share/home/xiehs/biosoft/SPAdes-3.15.3-Linux/share/spades/pyyaml3/constructor.py", line 46, in construct_document

    for dummy in generator:

  File "/share/home/xiehs/biosoft/SPAdes-3.15.3-Linux/share/spades/pyyaml3/constructor.py", line 398, in construct_yaml_map

    value = self.construct_mapping(node)

  File "/share/home/xiehs/biosoft/SPAdes-3.15.3-Linux/share/spades/pyyaml3/constructor.py", line 204, in construct_mapping

    return super().construct_mapping(node, deep=deep)

  File "/share/home/xiehs/biosoft/SPAdes-3.15.3-Linux/share/spades/pyyaml3/constructor.py", line 126, in construct_mapping

    if not isinstance(key, collections.Hashable):

AttributeError: module 'collections' has no attribute 'Hashable'

解决方案

       Python 3.10 版本 collections 将 等一些属性放到了 collections.abc 子模块下。所以会出现 collections’ has no attribute 的错误。

       找到最后报错的文件,一般是报错出现的最后一个文件。更改collections.attr 为 collections.abc.attr。

       /share/home/xiehs/biosoft/SPAdes-3.15.3-Linux/share/spades/pyyaml3/constructor.py文件中第126行

       attr 为报错中没有的属性,新增.abc.问题就解决了。

正文到此结束
本文目录