Can't import my own module distributed with distutils
<p>I'd like to package my application to share it between several projects.
My setup.py looks like this:</p>

<pre><code># -*- coding: utf-8 -*-
from distutils.core import setup

setup(
    name='foo_bar',
    version='1.0',
    py_modules=['foo_bar'],
    install_requires=[
        'bitstring==3.1.5',
        'pytz==2016.4',
        'wheel==0.24.0', ]
)
</code></pre>

<p>Then I run command</p>

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

<p>that creates tar.gz file for me</p>

<p>I'm having trouble with using my foo_bar application. I'm installing it into separate virtualenv via pip</p>

<pre><code>pip install dist/foo_bar.tar.gz
</code></pre>

<p>and output of pip freeze suggests that it is installed</p>

<pre><code>foo-bar==1.0
bitstring==3.1.5
pytz==2016.4
wheel==0.24.0
</code></pre>

<p>When I try to import this module in python console</p>

<pre><code>import foo_bar
</code></pre>

<p>I get <code>ImportError: No module named 'foo_bar'</code></p>

<p>What I'm missing?</p>

<p>Edit:</p>

<p>My file structure looks like this:</p>

<pre><code>foo_bar
âââ dist
âÂ Â  âââ foo_bar-1.0.tar.gz
âââ __init__.py
âââ MANIFEST
âââ bar.py
âââ requirements.txt
âââ setup.py
</code></pre>

<p>Could you provide your directory structure? Are you in the same virtualenv when you're trying to import your module? Why are you using <code>py_modules</code> and not <code>packages</code>?</p>

<p>Moreover, you're trying to import <code>foo_bar</code>, however there is no <code>foo_bar.py</code> in your package! Try to rename <code>bar.py</code> to that name.</p>

<p>Note: I've never used packages this way. Usually you create a package (directory with <code>__init__.py</code> file) on the same level as <code>setup.py</code> is. This means, that you would create another <code>foo_bar</code> dir in you project and there you would place <code>bar.py</code>. Then you would import it like <code>import foo_bar.bar</code>.</p>

python pip importerror distutils