“AttributeError: ‘module’ object has no attribute ‘blah’”

  • The obvious cause of this is that the settings.py doesn’t have the directory containing blah listed in INSTALLED_APPS.
  • A less obvious cause: you’ll also get this error if the directory doesn’t contain a file __init__.py.

13 Responses to ““AttributeError: ‘module’ object has no attribute ‘blah’””

  1. John says:

    Thanks! I would have never guessed that from the stack trace.

  2. Branko Vukelic says:

    I’m just having the same error, and either of those do not apply. I have the app listed in INSTALLED_APPS, and I have the __init__.py.

  3. macdet says:

    Yes, that was mine :( __init__.py

    Thx to google and you!

  4. Gustavo Rahal says:

    In my case the reason was dirt .pyc files hanging around. I cleaned all pyc files and it worked

  5. lacking imsave() says:

    I’m new to the whole python world, but im having this same type of problem:

    —————————————————————————
    AttributeError Traceback (most recent call last)

    /Users/lzkelley/Programs/Biophysics/Templates/nc_make_ffts.py in ()
    55 fft_image /= m
    56
    —> 57 misc.imsave(“fft”+str(num_images)+”.png”,fft_image)
    58
    59

    AttributeError: ‘module’ object has no attribute ‘imsave’
    WARNING: Failure executing file:
    ————————————————————–

    and when i try to import the method explicitly

    —————————————————————————
    ImportError Traceback (most recent call last)

    /Users/lzkelley/Programs/Biophysics/Templates/nc_make_ffts.py in ()
    3 import pylab
    4 from scipy import *
    —-> 5 from scipy.misc import imsave
    6 from pylab import *
    7 import os

    ImportError: cannot import name imsave
    WARNING: Failure executing file:
    Python 2.5.4 (r254:67916, Apr 6 2009, 15:48:49)
    ————————————————-
    any thoughts?

  6. muslu says:

    i added settings.py and i include __init__.py in the folder but still have problem

  7. Anonymous says:

    Thanks so much! __init__.py was my problem :)

  8. snf says:

    just a brief note

    if you use import to include a module, make sure you don’t have a file named just the same as the module you are trying to include in current directory

    it seems that python takes preference for local files over modules thus import fails

    a rookie observation

    cheers

  9. Gnarlodious says:

    Thanks for the hint. In my case the script was named “Cookie”, the same as the module imported. One symptom was that I was getting double printing in both Terminal and browser.

  10. aksegaly says:

    this is my error
    attributeerror ‘module’ object has no attribute system
    help…

  11. aksegaly says:

    this is my error
    attributeerror ‘module’ object has no attribute system
    help…

  12. aksegaly says:

    this is my error
    attributeerror ‘module’ object has no attribute system
    affer the compilation
    help me…

  13. Pete says:

    thanks. my problem was that i had two versions of a python package (numpy). i was trying to invoke a method that was only in the new one, however it found the old package first, so it couldn’t locate the new method.

    anyway, your post got me looking in the right direction :)

Leave a Reply