AttributeError: module has no attribute

Aug 7, 2016

Below is the type of error I was getting when playing around with the basic getting-started Python samples:

AttributeError: module ‘threading’ has no attribute ‘Lock’

Full error:

Traceback (most recent call last):
  File "threading.py", line 1, in <module>
    import threading
  File "/PyDev/threading.py", line 15, in <module>
    counter = Counter()
  File "/PyDev/threading.py", line 6, in __init__
    self.lock = threading.Lock()
AttributeError: module 'threading' has no attribute 'Lock'

The reason for the error was explained on Stackoverflow

Module: A module is a file containing Python definitions and statements. The file name is the module name with the suffix .py appended.

Answer:

Do not name your .py file with the same name as an item from the standard library.