Prashant singh
Prashant singh

Reputation: 81

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

I've written an MLflow component to upload & log an artifact from a URL to WandB. I am trying to run the script inside a conda environment but unfortunately I am facing this error

File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\__init__.py", line 38, in <module>
    from wandb import sdk as wandb_sdk
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\sdk\__init__.py", line 12, in <module>
    from .wandb_init import init  # noqa: F401
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\sdk\wandb_init.py", line 29, in <module>
    from .backend.backend import Backend
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\sdk\backend\backend.py", line 18, in <module>
    from ..internal.internal import wandb_internal
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\sdk\internal\internal.py", line 34, in <module>
    from . import sender
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\sdk\internal\sender.py", line 18, in <module>
    from wandb.filesync.dir_watcher import DirWatcher
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\filesync\dir_watcher.py", line 10, in <module>
    wd_polling = util.vendor_import("watchdog.observers.polling")
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\util.py", line 170, in vendor_import
    module = import_module(name)
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\importlib\__init__.py", line 126, in import_module
    return _bootstrap._gcd_import(name[level:], package, level)
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\vendor\watchdog\observers\__init__.py", line 92, in <module>
    from .polling import PollingObserver as Observer
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\vendor\watchdog\observers\polling.py", line 43, in <module>
    from watchdog.observers.api import (
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\vendor\watchdog\observers\api.py", line 23, in <module>
    from watchdog.utils.bricks import SkipRepeatsQueue
  File "C:\anaconda\envs\mlflow-4b67c93d2a95df2e00cbf3c9f644d2e3dada00e0\lib\site-packages\wandb\vendor\watchdog\utils\bricks.py", line 175, in <module>
    class OrderedSet(collections.MutableSet):
AttributeError: module 'collections' has no attribute 'MutableSet'
2022/10/09 20:55:53 ERROR mlflow.cli: === Run (ID 'e5ad70e5104e4a50ad3f66a891bdbf81') failed ===

I've installed the WandB==0.13.2 & protobuf==3.20.3 & Mlflow latest version in my environment. I think it's happening because of dependency mismatch but not really sure.

Also, I've added the WandB & Protobuf in my conda.yml file for mlflow component script.

Thanks in advance.

Upvotes: 6

Views: 18928

Answers (2)

Atul
Atul

Reputation: 4340

I faced this issue on Ubuntu server which has Python 3.10 installed. The error was

"AttributeError: module 'collections' has no attribute 'MutableSet'"

And it came right at the line:

import openai

Although this line and rest of the script was not giving any problem on Python 3.12 which is my local machine. On the server however I got that nasty error. Here is detailed traceback:

File "/home/ubuntu/.local/lib/python3.10/site-packages/streamlit/runtime/scriptrunner/script_runner.py", line 600, in _run_script
    exec(code, module.__dict__)
File "/home/ubuntu/myfolder/mysubfolder/myscript.py", line 16, in <module>
    import openai
File "/home/ubuntu/.local/lib/python3.10/site-packages/openai/__init__.py", line 8, in <module>
    from . import types
File "/home/ubuntu/.local/lib/python3.10/site-packages/openai/types/__init__.py", line 5, in <module>
    from .batch import Batch as Batch
File "/home/ubuntu/.local/lib/python3.10/site-packages/openai/types/batch.py", line 7, in <module>
    from .._models import BaseModel
File "/home/ubuntu/.local/lib/python3.10/site-packages/openai/_models.py", line 24, in <module>
    from ._types import (
File "/home/ubuntu/.local/lib/python3.10/site-packages/openai/_types.py", line 21, in <module>
    import httpx
File "/home/ubuntu/.local/lib/python3.10/site-packages/httpx/__init__.py", line 2, in <module>
    from ._api import delete, get, head, options, patch, post, put, request, stream
File "/home/ubuntu/.local/lib/python3.10/site-packages/httpx/_api.py", line 6, in <module>
    from ._client import Client
File "/home/ubuntu/.local/lib/python3.10/site-packages/httpx/_client.py", line 32, in <module>
    from ._transports.default import AsyncHTTPTransport, HTTPTransport
File "/home/ubuntu/.local/lib/python3.10/site-packages/httpx/_transports/default.py", line 32, in <module>
    import httpcore
File "/home/ubuntu/.local/lib/python3.10/site-packages/httpcore/__init__.py", line 2, in <module>
    from ._async import (
File "/home/ubuntu/.local/lib/python3.10/site-packages/httpcore/_async/__init__.py", line 8, in <module>
    from .http2 import AsyncHTTP2Connection
File "/home/ubuntu/.local/lib/python3.10/site-packages/httpcore/_async/http2.py", line 8, in <module>
    import h2.connection
File "/usr/local/lib/python3.10/dist-packages/h2/connection.py", line 13, in <module>
    from hyperframe.frame import (
File "/usr/local/lib/python3.10/dist-packages/hyperframe/frame.py", line 17, in <module>
    from .flags import Flag, Flags
File "/usr/local/lib/python3.10/dist-packages/hyperframe/flags.py", line 14, in <module>
    class Flags(collections.MutableSet):

After lots of struggle of many many hours, I added this code and it started working.

import collections
if not hasattr(collections, 'MutableMapping'):
    import collections.abc
    collections.MutableMapping = collections.abc.MutableMapping

A typical problem of kind "It works on my machine". Then it was DLL hell now it is Version hell.

Python!

Upvotes: 0

RichardDufour
RichardDufour

Reputation: 71

I have this problem when I code with python, in the new version of python collections have no more MutableSet, MutableMapping, etc.. But the module collections.abc have it so if you want you can go like this:

import collections 
import sys
if sys.version_info.major == 3 and sys.version_info.minor >= 10:
    from collections.abc import MutableSet
    collections.MutableSet = collections.abc.MutableSet
else: 
    from collections import MutableSet

So I think that the version of wandb is maybe not compatible with this version of Python

Source : https://www.datasciencelearner.com/attributeerror-module-collections-has-no-attribute-mutablemapping/

Normally they fix it.. : https://github.com/wandb/wandb/issues/1503

Upvotes: 7

Related Questions