pip says it is a package, by python says it is not
<p>I am using Windows and have a directory like this:</p>

<pre><code>troopcalc/
    setup.py
    troopcalc/
        __init__.py
        troopcalc.py
        troopcfg.py
        tests/
            __init__.py
            test_troopcalc.py
            test_troopcfg.py
</code></pre>

<p>I used pip to install the package... and pip list shows the package installed and pointing to the top of the dir structure.</p>

<hr>

<p><code>troopcfg.py</code>:</p>

<pre><code>class TroopCfg(object):
...
</code></pre>

<hr>

<p><code>troopcalc.py</code>:</p>

<pre><code>from troopcalc.troopcfg import TroopCfg
</code></pre>

<hr>

<p><code>setup.py</code>:</p>

<pre><code>from setuptools import setup

setup(name='troopcalc',
    version='0.1',
    description='Calculates troop distribution',
    url='...',
    author='Randell ...',
    author_email='...',
    packages=['troopcalc', 'troopcalc.tests', 'troopcalc.data'],
    package_dir={'troopcalc': 'troopcalc', 'troopcalc.tests': 'troopcalc/tests', 'troopcalc.data': 'troopcalc/data'},
    package_data={'troopcalc.data': ['*.json']},
    )
</code></pre>

<hr>

<p>If I run <code>python .\troopcalc.py</code> I get the following:</p>

<pre><code>Traceback (most recent call last):
  File ".\troopcalc.py", line 2, in &lt;module&gt;
    from troopcalc.troopcfg import TroopCfg
  File "...\python\troopcalc\troopcalc\troopcalc.py", line 2, in &lt;module&gt;
    from troopcalc.troopcfg import TroopCfg
ImportError: No module named 'troopcalc.troopcfg'; 'troopcalc' is not a package
</code></pre>

<p>pip says it is a package, but python says it is not. The goal is not to use absolute paths of course. What am I missing?</p>

<p>Thanks.</p>

<blockquote>
  <p>If I run <code>python .\troopcalc.py</code> I get the following:</p>
</blockquote>

<p>Well, yes. Python thinks that <code>troopcalc</code> is <code>troopcalc.py</code>, since that's in the directories in <code>sys.path</code>.</p>

<pre><code>python -m troopcalc.troopcalc
</code></pre>

python