title: Installed python package empty except inside source directory
body: <p>I'm having trouble importing modules from a package I wrote and installed locally using setuptools. I seem to end up with an empty package unless I explicitly import modules in my <code>__init__.py</code>, and even then, it only imports stuff if I'm <code>cd</code>'d into the package's source directory.</p>
  
  <p>Here's my package structure</p>
  
  <pre><code>foo_project/
  |-- setup.py
  |-- foo/
  |-- |-- __init__.py
  |-- |-- moduleA.py
  |-- |-- moduleB.py
  |-- |-- ...
  </code></pre>
  
  <p>I'm using <code>virtualenvwrapper</code>, and want to install the above package in some environment <code>ENV</code>, and intend to be able to import the module in some other directory <code>foo_examples</code>.</p>
  
  <p>To begin with, my <code>__init__.py</code> is empty. To install, I:</p>
  
  <ul>
  <li>run <code>workon ENV</code> to activate the virtual environment</li>
  <li><code>cd</code> into <code>foo_project</code></li>
  <li>run <code>python setup.py install</code></li>
  </ul>
  
  <p>The package seems to successfully install; I can even inspect the egg in <code>~/.virtualenvs/ENV/lib/python3.4/site-packages</code>, and it seems to have all the right files.</p>
  
  <p>But, when I try to import the module, it appears empty:</p>
  
  <pre><code>&gt;&gt;&gt; import foo
  &gt;&gt;&gt; dir(foo)
  ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
  &gt;&gt;&gt; foo.moduleA
  AttributeError: 'module' object has no attribute 'moduleA'
  </code></pre>
  
  <p>If, however, I explicitly import my modules in the <code>__init__.py</code>, they become accessible:</p>
  
  <p>In <code>__init__.py</code>:</p>
  
  <pre><code>from . import moduleA, moduleB, ...
  </code></pre>
  
  <p>Then:</p>
  
  <pre><code>from foo import moduleA
  </code></pre>
  
  <p>Doesn't throw an error, but only if I'm still in the packages source directory. If I <code>cd</code> one level up, I get the same problem.</p>
  
  <pre><code>$ cd ..
  $ python
  &gt;&gt;&gt; import foo
  &gt;&gt;&gt; dir(foo)
  ['__builtins__', '__cached__', '__doc__', '__file__', '__loader__', '__name__', '__package__', '__path__', '__spec__']
  &gt;&gt;&gt; foo.moduleA
  AttributeError: 'module' object has no attribute 'moduleA'
  </code></pre>
  
  <p>I tried looking for related questions, but no luck. I suspect it's either a small error or I'm going about this the wrong way altogether. I'd be grateful for some help. Thanks.</p>