Difference between adding path to PYTHONPATH and installing your own module
<p>I'm working on a python project that contains a number of routines I use repeatedly. Instead of rewriting code all the time, I just want to update my package and import it; however, it's nowhere near done and is constantly changing. I host the package on a repo so that colleagues on various machines (UNIX + Windows) can pull it into their local repos and use it.</p>

<p>It sounds like I have two options, either I can keeping installing the package after every change or I can just add the folder directory to my system's path. If I change the package, does it need to be reinstalled? <a href="http://www.kennethreitz.org/essays/repository-structure-and-python" rel="nofollow">I'm using this blog post as inspiration</a>, but the author there doesn't stress the issue of a continuously changing package structure, so I'm not sure how to deal with this.</p>

<p>Also if I wanted to split the project into multiple files and bundle it as a package, at what level in the directory structure does the PTYHONPATH need to be at? To the main project directory, or the .sample/ directory?</p>

<pre><code>README.rst
LICENSE
setup.py
requirements.txt
sample/__init__.py
sample/core.py
sample/helpers.py
docs/conf.py
docs/index.rst
tests/test_basic.py
tests/test_advanced.py
</code></pre>

<p>In this example, I want to be able to just import the package itself and call the modules within it like this:</p>

<pre><code>import sample

arg = sample.helper.foo()
out = sample.core.bar(arg)

return out
</code></pre>

<p>Where core contains a function called foo</p>

<p>PYTHONPATH is a valid way of doing this, but in my (personal) opinion it's more useful if you have a whole different place where you keep your python variables. Like <code>/opt/pythonpkgs</code> or so.</p>

<p>For projects where I want it to be installed and also I have to keep developing, I use <code>develop</code> instead of <code>install</code> in setup.py:</p>

<p>When installing the package, don't do:</p>

<pre><code>python setup.py install
</code></pre>

<p>Rather, do:</p>

<pre><code>python setup.py develop
</code></pre>

<p>What this does is that it creates a synlink/shortcut (I believe it's called egglink in python) in the python libs (where the packages are installed) to point to your module's directory. Hence, as it's a shortcut/symlink/egglink when ever you change a python file, it will immediately reflect the next time you import that file.</p>

<p>Note: Using this, if you delete the repository/directory you ran this command from, the package will cease to exist (as its only a shortcut)</p>

<p>The equivalent in <code>pip</code> is -e (for editable):</p>

<pre><code>pip install -e .
</code></pre>

<p>Instead of:</p>

<pre><code>pip install .
</code></pre>

python module packaging