How do symbolic links affect the way Python finds modules?
<p>The environment variable <code>PYTHONPATH</code> is set to <code>$HOME/lib/python</code>.</p>

<p>The file tree in <code>$PYTHONPATH</code> looks like this</p>

<pre><code>foo/
    __init__.py
    bar.py         
</code></pre>

<p>both files are empty.</p>

<p>Now I create a simple script containing </p>

<pre><code>#!/usr/bin/env python

print __file__
import bar
</code></pre>

<p>and save it as <code>baz.py</code>. If I run the script anywhere other than
in <code>$PYTHONPATH/foo</code> it fails to locate module <code>bar</code>.</p>

<p>However if I move the file to <code>$PYTHONPATH/foo</code> and create a symbolic link
to that file, I can run it from anywhere. For example:</p>

<pre><code>$ cd /tmp
$ ln -s $PYTHONPATH/foo/baz.py baz
$ ./baz
./baz
$
</code></pre>

<p>Yet <code>__file__</code> is set to <code>./baz</code>. So how does Python find module bar?</p>
