title: Mtaplotlib AttributeError: 'module' object has no attribute 'pyplot'
body: <p>Before anyone says "duplicate question" or anything, please read on, it's not the same as other questions.</p>
  
  <p>So when i run my small program;</p>
  
  <pre><code>python numbers.py
  </code></pre>
  
  <p>where</p>
  
  <pre><code>$ file `which python`
  /usr/bin/python: symbolic link to 'python2.7'
  
  $ file `which python2.7`
  /usr/bin/python2.7: ELF 64-bit LSB executable, x86-64, version 1 (SYSV), dynamically linked (uses shared libs), for GNU/Linux 2.6.24, BuildID[sha1]=0x623b662458af705775fcbd2576ca06eaa82bc482, stripped
  </code></pre>
  
  <p>and i'm using matplotlib version 1.2;</p>
  
  <pre><code>/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-x86_64.egg/
  </code></pre>
  
  <p>I have tried several approaches to get it to work;</p>
  
  <pre><code>from matplotlib import pyplot as plt
  import matplotlib.pyplot as plt
  </code></pre>
  
  <p>neither of them work. they both give the same error;</p>
  
  <pre><code>$ python numbers.py
  Traceback (most recent call last):
    File "numbers.py", line 1, in &lt;module&gt;
      import matplotlib.pyplot as plt
    File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-x86_64.egg/matplotlib/pyplot.py", line 26, in &lt;module&gt;
      from matplotlib.figure import Figure, figaspect
    File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-x86_64.egg/matplotlib/figure.py", line 34, in &lt;module&gt;
      import matplotlib.colorbar as cbar
    File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-x86_64.egg/matplotlib/colorbar.py", line 29, in &lt;module&gt;
      import matplotlib.collections as collections
    File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-x86_64.egg/matplotlib/collections.py", line 23, in &lt;module&gt;
      import matplotlib.backend_bases as backend_bases
    File "/usr/local/lib/python2.7/dist-packages/matplotlib-1.2.0-py2.7-linux-x86_64.egg/matplotlib/backend_bases.py", line 51, in &lt;module&gt;
      from PIL import Image
    File "/usr/local/lib/python2.7/dist-packages/PIL/Image.py", line 90, in &lt;module&gt;
      import numbers
    File "/home/will/Documents/python/numbers/numbers.py", line 1, in &lt;module&gt;
      import matplotlib.pyplot as plt
  AttributeError: 'module' object has no attribute 'pyplot'
  </code></pre>
  
  <p>What is really frustrating, is that i have another file, with <code>from matplotlib import pyplot as plt</code> at the top, and it works fine. I can't see any reason why one would work and the other wouldn't...</p>
  
  <p>I tried changing the file name too, so that it wasn't <code>numbers.py</code> but that didnt' work either.</p>
  
  <p><strong>Has anyone come across this before and fixed it? Or know why it doesn't work?</strong></p>
  
  <p>Here's the full file:</p>
  
  <pre><code>from matplotlib import pyplot as plt
  
  
  def toString(number):
      if type(number) == float:
          return floatToString(number)
      elif type(number) == int:
          return intToString(number)
      elif type(number) == complex:
          return complexToString(number)
      else:
          return "NaN"
  
  
  def intToString(number):
      if number &lt; 0:
          return "minus " + intToStringPos(abs(number))
      else:
          return intToStringPos(number)
  
  def intToStringPos(number):
      upTo20 = [""] + "one two three four five six seven eight nine ten eleven twelve thirteen fourteen fifteen sixteen seventeen eighteen nineteen".split()
      tenTimes = "twenty thirty fourty fifty sixty seventy eighty ninety hundred".split()
      logs = [""] + "thousand million billion trillion quadrillion".split()
  
      if len(str(number)) &gt; 3:
          #split number into groups of three, from the right hand end    
          number = list(reversed(str(number)))
  
          groups = list(reversed([int("".join(reversed([number[i+j] for j in range(3) if i+j &lt; len(number)]))) for i in range(0, len(number), 3)]))
  
          retString = ""
          for i, number in enumerate(reversed(groups)):
              if number == 0:
                  continue
              elif i == 0 and len(str(number)) &lt; 3:
                  if number != 0:
                      retString = "and " + intToString(number)
              else:
                  retString = intToString(number) + " " + logs[i] + " " + retString
  
          return retString.strip()
  
      elif 1000 &gt; number &gt; 99:
          tens = intToString(int(str(number)[1:]))
          if tens != "zero":
              return upTo20[number/100] + " hundred and " + tens
          else:
              return upTo20[number/100]
  
      elif 100 &gt; number &gt;= 20:
          return tenTimes[number/10-2] + " " + upTo20[number - 10*(number/10)]
  
      elif 0 &lt; number &lt; 20:
          return upTo20[number]
  
      elif number == 0:
          return "zero"
  
  def floatToString(number):
      integerPart, decimalPart = divmod(number,1)
      retString = intToString(int(integerPart))
      if decimalPart &gt; 0.0:
           return retString + " point " + " ".join([intToString(int(d)) for d in str(decimalPart)[2:]])
      else:
           return retString
  
  def complexToString(number):
      retString = []
      if number.real &gt; 0.0:
          retString.append(floatToString(number.real))
      if number.imag &gt; 0.0:
          if number.imag == 1:
              retString.append("j")
          else:
              retString.append(floatToString(number.imag) + " j")
  
      return " plus ".join(retString)
  
  
  lengths = []
  for number in range(1000):
      print toString(number)      
      lengths.append(len(toString(number)))
  
  print lengths
  
  plt.plot(range(1000), lengths)
  plt.pyplot.show()
  </code></pre>