“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.


  • John

    Reply Reply May 15, 2008

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

  • Branko Vukelic

    Reply Reply June 22, 2008

    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.

  • macdet

    Reply Reply July 13, 2008

    Yes, that was mine :( __init__.py

    Thx to google and you!

  • Gustavo Rahal

    Reply Reply January 5, 2009

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

    • mangesh

      Reply Reply March 24, 2014

      thanks….worked for me too…

  • lacking imsave()

    Reply Reply April 6, 2009

    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
    —> 57 misc.imsave(“fft”+str(num_images)+”.png”,fft_image)

    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?

  • muslu

    Reply Reply April 29, 2009

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

  • Anonymous

    Reply Reply June 22, 2009

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

  • snf

    Reply Reply August 9, 2009

    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


    • Jordan

      Reply Reply December 12, 2012

      That is a great observation, thanks. That was exactly what was happening to me. Thanks again!!

      • mar

        Reply Reply December 30, 2012

        Thanks so much!
        That was exactly my problem.

    • Vincent Khougaz

      Reply Reply August 1, 2013

      This was my issue. Plebeian mistake.

    • Erin

      Reply Reply January 4, 2014

      Wow, that worked for me. Took me quite awhile to figure it out! Thank you so much.

  • Gnarlodious

    Reply Reply September 5, 2009

    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.

  • aksegaly

    Reply Reply October 24, 2009

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

  • aksegaly

    Reply Reply October 24, 2009

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

  • aksegaly

    Reply Reply October 24, 2009

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

  • Pete

    Reply Reply January 15, 2010

    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 :)

  • Dan

    Reply Reply August 14, 2010

    Anyone here know how I can pass a regexp this module?:

    import re

    def htc(m):
    return chr(int(m.group(1),16))

    def urldecode(url):
    return rex.sub(htc,url)

    if __name__ == ‘__main__':
    print urldecode(‘adasasdasd%20asdasdasdas’)

    Using re.urldecode gives me the same “‘module’ object has no attribute” error but I’m new at this and don’t really know what I’m doing. The module seem to work fine I just can’t figure out how to pass a regexp to urldecode. Example:



    print urldecode(‘match’)

    Thanks for any help.

  • Anonymous

    Reply Reply April 5, 2011

    I am seeing the replies as below
    Thanks so much! __init__.py was my problem…

    Can anyone explain me the problem of __init__.py problem?

  • masood

    Reply Reply October 3, 2011


    how to call java method in python

    please help me :-(

  • 4F2E4A2E

    Reply Reply October 25, 2011

    im my case i had the _init_.py, but it had some content like this:

    import settings
    import ldap
    CAN_USE = True
    CAN_USE = False

    so i removed it and everything is fine now…

  • Lijo

    Reply Reply May 11, 2012

    I have this wierd kind of error.
    I couldn’t find an answer for this anywhere.

    AttributeError: ‘module’ object has no attribute ‘walk’

    This happened when I tried to execute this command.
    for subdir,dir,files in os.walk(‘H:/Project/’):
    #print subdir
    #print dir
    #print files

    for file in files:
    if file == file_name:

    any help is appreciated !

  • bams

    Reply Reply June 8, 2012

    well thanks snf.
    In my case i had a python file random.py and was trying to import random module. Just deleting the py file really helped.

  • bams

    Reply Reply June 8, 2012

    also someone talked about double printing, i had been wondering since a while why that was happening.

  • hobs

    Reply Reply October 30, 2012

    For me the problem was old pyc’s all over the place in Mac OS X.

    To double-check a find command on the pyc’s:

    cd /usr/local/lib/python2.7
    find . -type f -name “*.pyc” -exec sudo echo {} \;

    Once you’re happy with the list of files, delete them with:

    find . -type f -name “*.pyc” -exec rm -f {} \;

  • maverik

    Reply Reply December 6, 2012

    when i try to import pylab i have the following error
    Traceback (most recent call last):
    File “”, line 1, in
    File “/usr/lib/pymodules/python2.7/pylab.py”, line 1, in
    from matplotlib.pylab import *
    File “/usr/lib/pymodules/python2.7/matplotlib/pylab.py”, line 221, in
    from matplotlib import mpl # pulls in most modules
    File “/usr/lib/pymodules/python2.7/matplotlib/mpl.py”, line 3, in
    from matplotlib import axes
    File “/usr/lib/pymodules/python2.7/matplotlib/axes.py”, line 8539, in
    Subplot = subplot_class_factory()
    File “/usr/lib/pymodules/python2.7/matplotlib/axes.py”, line 8531, in subplot_class_factory
    new_class = new.classobj(“%sSubplot” % (axes_class.__name__),
    AttributeError: ‘module’ object has no attribute ‘classobj’

    but if i try to import from the directory /usr/lib/python2.7/ it works fine what can be the possible problem

  • Amir

    Reply Reply December 10, 2012

    Can any Body help me with this error.
    I was running OPAddon.py (Tor Network Analysis Tool) and I got the below error.

    Traceback (most recent call last):
    File “./op-addon.py”, line 1366, in
    File “./op-addon.py”, line 1196, in startup
    GeoIPSupport.GeoIPRouter, True)
    File “./op-addon.py”, line 626, in __init__
    self.model = NetworkModel(self.routers)
    File “./op-addon.py”, line 379, in __init__
    self.graph = networkx.XGraph(name=”Tor Subnet”)
    AttributeError: ‘module’ object has no attribute ‘XGraph’

  • Brandon Bertelsen

    Reply Reply December 23, 2012

    Another possibility is that you’ve called:

    def __unicode__(self):
    return self.name

    At the end of your model unnecessarily.

  • zi

    Reply Reply April 25, 2013

    I have this error in my python script for abaqus:
    attribute error:’constrained sketch’ object has no attribute ‘line’

    import sketch
    import part

    import connectorBehavior

    myModel = mdb.Model(name=’Model GNP-3D’)
    RVESketch = myModel.ConstrainedSketch(name=’Sketch RVE’, sheetSize=200.0)
    RVE = myModel.Part(name=’RVE’, dimensionality=THREE_D, type=DEFORMABLE_BODY)
    RVE.BaseSolidExtrude(sketch=RVESketch, depth=RVE_size[2])
    for i in range(NUM_GNP):
    GNPSketch = myModel.ConstrainedSketch(name=GNPname, sheetSize=200.0)
    GNPSketch.ConstructionLine(point1=(0.0,-100.0), point2=(0.0, 100.0))
    GNPSketch.FixedConstraint(entity = GNPSketch.geometry[2])
    GNPSketch.EllipseByCenterPerimeter(axisPoint1=(0.0, a), axisPoint2=(b, 0.0), center=(0.0, 0.0))
    GNPSketch.CoincidentConstraint(addUndoState=False, entity1=GNPSketch.vertices[0], entity2=GNPSketch.geometry[2])
    GNPSketch.CoincidentConstraint(addUndoState=False, entity1=GNPSketch.vertices[2], entity2=GNPSketch.geometry[2])
    GNPSketch.VerticalConstraint(addUndoState=False, entity=GNPSketch.geometry[5])
    GNPSketch.ParallelConstraint(addUndoState=False, entity1=GNPSketch.geometry[2],entity2=GNPSketch.geometry[5])
    GNPSketch.CoincidentConstraint(addUndoState=False, entity1= GNPSketch.vertices[3], entity2=GNPSketch.geometry[2])
    GNPSketch.autoTrimCurve(curve1=GNPSketch.geometry[3], point1=(-b,0.0))
    GNP=myModel.Part(name=GNPname, dimensionality=THREE_D, type=DEFORMABLE_BODY)
    GNP.BaseSolidRevolve(angle=360,flipRevolveDirection=OFF, sketch=GNPSketch)

  • Ravi

    Reply Reply May 1, 2013

    You all need to check your python version, subprocess check_output issue has been fixed into python 2.7 +

  • mylanium

    Reply Reply August 12, 2013

    There are a lot of different reasons,
    and none among mentioned is mine (cyclic import). So to solve the problem, I’ve ran ./manage.py shell –trace
    The –trace option let you see the traceback and catch the reason of the problem!

  • Xavante

    Reply Reply January 19, 2014

    Thank you for this thread!! I got so frustrated with this problem that I reinstalled my OS twice to try fix it…

    Turns out it was a simple matter of renaming the modules with the same names in the base directory :( :(

    Thanks again – lifesaver @RachelWillmer, and @snf

  • Brian B

    Reply Reply February 23, 2014

    My problem was having a script named “io.py” in my project directory. After renaming this file, it worked. My error was:

    AttributeError: ‘module’ object has no attribute ‘BufferedIOBase’

  • Braulio

    Reply Reply February 28, 2014

    Another cause

    When you don’t write a module name correctly.

  • ADotiyal

    Reply Reply May 9, 2014

    I am getting this error:

    I am doing just:

    import sqlanydb

    When compiling it gives this error message:

    File “build/bdist.solaris-2.10-i86pc/egg/sqlanydb.py”, line 419, in __init__
    File “build/bdist.solaris-2.10-i86pc/egg/sqlanydb.py”, line 413, in load_library
    sqlanydb.InterfaceError: Could not load dbcapi. Tried: dbcapi.dll,libdbcapi_r.so,libdbcapi_r.dylib
    Exception AttributeError: “‘Root’ object has no attribute ‘api'” in <bound method Root.__del__ of > ignored

    Can anyone help?

  • Eric

    Reply Reply June 2, 2014

    Thanks for this.. I learned this about modules awhile ago, but rarely am I writing my own modules in Python. Maybe there is room for improvement in the stack trace error with this one?

    This –> “A less obvious cause: you’ll also get this error if the directory doesn’t contain a file __init__.py.”

  • panu

    Reply Reply July 10, 2014

    Can someone tell me where I can find this setting.py file?

    • panu

      Reply Reply July 10, 2014

      meant settings.py

  • Tarun

    Reply Reply July 23, 2014

    can anybody help in this
    to run i am applying python Desktop\ex27.py 5555 firefox WINDOWS

    an error i am getting

    AttributeError: ‘module’ object has no attribute ‘5555’

    more {Traceback (most recent call last):
    File “Desktop\ex27.py”, line 31, in
    File “C:\Python27\lib\unittest\main.py”, line 94, in __init__
    File “C:\Python27\lib\unittest\main.py”, line 149, in parseArgs
    File “C:\Python27\lib\unittest\main.py”, line 158, in createTests
    File “C:\Python27\lib\unittest\loader.py”, line 130, in loadTestsFromNames
    suites = [self.loadTestsFromName(name, module) for name in names]
    File “C:\Python27\lib\unittest\loader.py”, line 100, in loadTestsFromName
    parent, obj = obj, getattr(obj, part)
    AttributeError: ‘module’ object has no attribute ‘5555’
    from selenium import webdriver
    import unittest
    import sys
    from sys import argv

    class ExampleTestCase(unittest.TestCase):
    capabilities = None

    def setUp(self):
    self.driver = webdriver.Remote(command_executor=”http://x.x.x.x:5555/wd/hub”, desired_capabilities={ “browserName”: browser, “platform”: platform, “node”:node })

    def test_example(self):
    print self.driver.title
    self.assertEqual(self.driver.title, “Google”)

    def tearDown(self):

    if __name__ == “__main__”:
    args = sys.argv

    node = args[1]

    browser = args[2]

    platform = args[3]


  • Ryan Currah

    Reply Reply August 5, 2014

    I’m getting AttributeError: ‘module’ object has no attribute ‘CELERY’
    with celery in my project.

Leave A Response

* Denotes Required Field