ProjectStack
python

AttributeError: module has no attribute

You tried to access a function, class, or variable from a module that doesn't exist in it. The name is either misspelled, doesn't exist in that module, or was removed in a newer version.

Common causes

  • A typo in the attribute name — attribute names are case-sensitive
  • The function was moved to a different submodule in a newer package version
  • You imported the module under a different name than expected
  • Your file has the same name as the module you're importing, shadowing the real module

How to fix it

  1. Check the module's documentation or use dir(module) to see what's available
  2. Verify the spelling and case: urllib.parse not urllib.Parse
  3. Check if the function moved to a submodule: from module.sub import func
  4. Make sure your script file isn't named the same as the module you're importing (e.g. don't name your file random.py)

Example

Traceback (most recent call last): File "app.py", line 2, in <module> os.makedirs_exist_ok('/tmp/test') AttributeError: module 'os' has no attribute 'makedirs_exist_ok'

Calling a misremembered function name — the correct call is os.makedirs('/tmp/test', exist_ok=True)

Have a different error?

Paste any error message into the Error Translator to get an instant explanation.