title: Python - os.path doesn't exist: AttributeError: 'module' object has no attribute 'path'
body: <p>Investigating a strange error that I started getting all of a sudden with gdb-python, I reduced it down to this:</p>
  
  <pre><code>C:\Users\User&gt;python -i
  Python 2.7.3 (default, Apr 10 2012, 23:31:26) [MSC v.1500 32 bit (Intel)] on win 32
  Type "help", "copyright", "credits" or "license" for more information.
  &gt;&gt;&gt; import os
  &gt;&gt;&gt; dir(os.path)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
  AttributeError: 'module' object has no attribute 'path'
  &gt;&gt;&gt; dir(os)
  ['__builtins__', '__doc__', '__file__', '__name__', '__package__']
  </code></pre>
  
  <p>Looking through some other <code>'module' object has no attribute</code> answers, the most common suggestion is that there must be another rogue <code>os.py</code> somewhere in <code>sys.path</code>, and that it was getting loaded, rather than the built-in one. But I checked in <code>PYTHONPATH</code> environment variable, and in the current directory, and there wasn't any other <code>os.py</code>.</p>
  
  <p>So I looked for a way to find the name of the file where an entity was defined, and unsurprisingly, Python has <a href="https://stackoverflow.com/a/427533/1143274">such a facility</a> in the form of the <code>inspect</code> module.</p>
  
  <pre><code>&gt;&gt;&gt; inspect.getsourcelines(os)
  Traceback (most recent call last):
    File "&lt;stdin&gt;", line 1, in &lt;module&gt;
    File "C:\Programs\Python273\lib\inspect.py", line 690, in getsourcelines
      lines, lnum = findsource(object)
    File "C:\Programs\Python273\lib\inspect.py", line 527, in findsource
      sourcefile = getsourcefile(object)
    File "C:\Programs\Python273\lib\inspect.py", line 451, in getsourcefile
      if os.path.exists(filename):
  AttributeError: 'module' object has no attribute 'path'
  </code></pre>
  
  <p>So <code>inspect</code> was relying on <code>os.path</code>, and then I ran out of ideas.</p>
  
  <p>I haven't installed anything new recently. The only thing that happened was a forced shutdown that I had to do, which might have coincided with running a Python script, since I was running a short Python script in a loop repeatedly when the machine became unresponsive and the forced shutdown occurred.</p>