Search code examples
pythondefaultdict

ImportError: cannot import name defaultdict


I'm getting this really strange ImportError when running from collections import defaultdict:

ImportError: cannot import name defaultdict

I'm running python 2.7, and the strange part is that in other parts of my application this exact same import line succeeds.

I thought maybe that's a circular import, but it doesn't make much sense when it comes to built-in python modules.

Any ideas why I get this error?


Solution

  • You probably have a module named 'collections' in your project.

    Try renaming this module in your project.