Sign Up

Sign Up to our social questions and Answers Engine to ask questions, answer people’s questions, and connect with other people.

Have an account? Sign In

Have an account? Sign In Now

Sign In

Login to our social questions & Answers Engine to ask questions answer people’s questions & connect with other people.

Sign Up Here

Forgot Password?

Don't have account, Sign Up Here

Forgot Password

Lost your password? Please enter your email address. You will receive a link and will create a new password via email.

Have an account? Sign In Now

You must login to ask a question.

Forgot Password?

Need An Account, Sign Up Here

Please briefly explain why you feel this question should be reported.

Please briefly explain why you feel this answer should be reported.

Please briefly explain why you feel this user should be reported.

Questions and answers begin here Logo Questions and answers begin here Logo
Sign InSign Up

Questions and answers begin here

Search
Ask A Question

Mobile menu

Close
Ask a Question
  • Home
  • About Us
  • Blog
  • Contact Us

AttributeError: module ‘collections’ has no attribute ‘MutableMapping’

Home/ Questions/Q 443
Next
Answered
AttributeError: module 'collections' has no attribute 'MutableMapping'
juditmoraga
juditmoraga Teacher

I’m having a strange problem with my code that involves the use of the `MutableMapping` function from the `collections` module. I’ve imported the module like this:
“`
import collections
“`
But when I try to call the `MutableMapping` function in my code like this:
“`
my_mapping = collections.MutableMapping()
“`
I get this error message: “AttributeError: module ‘collections’ has no attribute ‘MutableMapping'”.
I’ve been scratching my head over this for a while and I can’t seem to figure out what’s going on. I’ve tried looking up the error message and browsing through the Python documentation, but I haven’t found anything helpful. It seems like the `collections` module should have the `MutableMapping` function, so I don’t understand why I’m getting this error.

I suspect that there’s something wrong with the way I’m importing the `collections` module or that there’s some other module that’s conflicting with it. But I’m not sure where to start looking for the source of the problem. Can anyone offer any advice on how I can troubleshoot this error? I’m relatively new to programming, so I apologize if I’m missing something obvious. Thank you in advance for your help!

attributeerrorcollectionserror messagemutable mappingpython
  • 666
  • 0 Followers
  • 1
  • Report
Leave an answer

Leave an answer
Cancel reply

Browse

4 Answers

  • Voted
  • Oldest
  • Recent
  • Random
  1. Best Answer
    juanpin_2107 Teacher
    2018-12-16T17:58:05+00:00Added an answer about 4 years ago

    Hey there! I came across your question and I think I can help you out. It seems like you are getting an “AttributeError” when using “collections.MutableMapping” in your code. This error occurs when Python is unable to find an attribute or method within a particular module or package.
    In your case, it looks like you may be running an outdated version of Python. Starting with Python 3.3, “collections.Mapping” and “collections.MutableMapping” were changed to abstract base classes, which means that they cannot be instantiated directly. Instead, you need to use a concrete implementation of these classes. For example, try using “dict” instead of “collections.MutableMapping” in your code and see if the error disappears.
    If you really need to use “collections.MutableMapping” for your application, you can try upgrading your Python installation to version 3.3 or later. Alternatively, you can install the “collections-extended” package that backports the abstract base classes to earlier versions of Python.
    It’s also possible that your code is importing the wrong module. Make sure that you are importing “collections” and not another module with a similar name. You can check this by printing out the value of “__name__” in the module where you are using “collections.MutableMapping”.
    Overall, the AttributeError that you are experiencing in your code is likely due to a version mismatch or a module name clash. By using the correct implementation of “collections.Mapping” and “collections.MutableMapping” or upgrading your Python installation, you should be able to get your code working again without encountering this error. Good luck!

    • 52
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  2. marielavb2 Begginer
    2018-12-22T23:19:50+00:00Added an answer about 4 years ago

    One possible solution to the problem you’re facing is to import the `MutableMapping` class from the `typing` module and use it instead of the `collections.MutableMapping` class. This will allow you to access the functionality you need without encountering the `AttributeError` you’ve been experiencing.
    Here’s some example code that demonstrates this solution:
    “`
    from typing import MutableMapping
    class MyMapping(MutableMapping):
    # Define the required abstract methods
    …
    my_mapping = MyMapping()
    my_mapping[‘key’] = ‘value’
    “`
    I hope this solution works for you. If you have any further questions or run into any issues, feel free to ask. Good luck with your coding!

    • 19
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  3. krlost42 Teacher
    2018-12-31T17:32:11+00:00Added an answer about 4 years ago

    I suggest that you check if you have misspelled the module name when importing the `collections` module. Double-check and make sure that you did not type `collection` which will raise an `AttributeError` when you try to use the `MutableMapping` function.

    Another possibility is that there could be another file in your project named “collections.py”. When the program imports the `collections` module, it might import this file instead of the built-in module. Having a file with the same name as the built-in module can cause confusion in the interpreter and might raise an `AttributeError`.

    If none of these solutions apply to your problem, please provide more information on the context of the error in your code so that I can help you further.

    • 18
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report
  4. dennis_bocanegra Teacher
    2018-12-26T11:05:21+00:00Added an answer about 4 years ago

    One possible solution to the attribute error you’re facing with collections might be to check the version of the Python module you’re using. In some cases, it can be an issue with older versions of the module. You can update or reinstall the module to see if it resolves the issue. Another possible solution is to check if you have accidentally named your file `collections.py` which might result in the interpreter importing that file instead of the module.

    Furthermore, ensure that the way you are referencing the MutableMapping object matches what is introduced in Python 2.7. For example, `collections.MutableMapping()` should be changed to `collections.abc.MutableMapping()`, which was introduced in Python 3.x, but also available in Python 2.7.

    Additionally, check to ensure that you’re not working with a partially installed version of Python or a broken Python installation, and that the module you’re trying to import is accessible by your Python interpreter. This can happen if you have multiple versions of Python installed or if your environment variables are not properly configured.

    In my experience, the attribute error with collections is usually caused by either version conflicts or issues with file and module naming conventions. I hope this helps and let me know if you have any further questions or concerns.

    • 14
    • Reply
    • Share
      Share
      • Share onFacebook
      • Share on Twitter
      • Share on LinkedIn
      • Share on WhatsApp
      • Report

Insert/edit link

Enter the destination URL

Or link to existing content

    No search term specified. Showing recent items. Search or use up and down arrow keys to select an item.