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

42 thoughts on ““AttributeError: ‘module’ object has no attribute ‘blah'””

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

    1. Just saved my day!
      Had .pyc files and got print from them and thinking why is it printing stuff from other files…!


  2. 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?

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


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

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

  6. 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 🙂

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

  8. 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?

  9. 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…

  10. 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 !

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

  12. 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 {} \;

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

  14. 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’

  15. 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)

  16. 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!

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

  18. 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’

  19. 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?

  20. 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.”

  21. 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]


Leave a Reply

Your email address will not be published. Required fields are marked *