title: PYTHONPATH vs. sys.path
body: <p>Another developer and I disagree about whether <code>PYTHONPATH</code> or <code>sys.path</code> should be used to allow Python to find a Python package in a user (e.g., development) directory.</p>
  <p>We have a Python project with a typical directory structure:</p>
  <pre><code>Project
      setup.py
      package
          __init__.py
          lib.py
          script.py
  </code></pre>
  <p>In script.py, we need to do <code>import package.lib</code>.  When the package is installed in site-packages, script.py can find <code>package.lib</code>.</p>
  <p>When working from a user directory, however, something else needs to be done.  My solution is to set my <code>PYTHONPATH</code> to include <code>&quot;~/Project&quot;</code>.  Another developer wants to put this line of code in the beginning of script.py:</p>
  <pre><code>sys.path.append(os.path.dirname(os.path.dirname(os.path.abspath(__file__))))
  </code></pre>
  <p>So that Python can find the local copy of <code>package.lib</code>.</p>
  <p>I think this is a bad idea, as this line is only useful for developers or people running from a local copy, but I can't give a good reason why it is a bad idea.</p>
  <p>Should we use <code>PYTOHNPATH</code>, <code>sys.path</code>, or is either fine?</p>