setup.py console_scripts entry point does not resolve import
<p>I have following setup.py:</p>

<pre><code>from setuptools import setup
from distutils.core import setup
setup(
    name="foobar",
    version="0.1.0",
    author="Batman",
    author_email="batman@gmail.com",
    packages = ["foobar"],
    include_package_data=True,
    install_requires=[
        "asyncio",
    ],
    entry_points={
        'console_scripts': [
            'foobar = foobar.__main__:main'
         ]
    },
)
</code></pre>

<p>Now, the <strong>main</strong>.py file gets installed and callable by foobar out of console after installation, which is what I wanted. Problem is, <strong>main</strong>.py has import at line 3 and that does not work. </p>

<p>So my folder structure is as follows</p>

<pre><code>dummy/setup.py
dummy/requirements.txt
dummy/foobar/__init__.py
dummy/foobar/__main__.py
dummy/foobar/wont_be_imported_one.py
</code></pre>

<p>I run <code>python3 setup.py bdist</code> being in dummy directory.
Upon running foobar after installation, I get error </p>

<pre><code>File "/usr/local/bin/foobar", line 9, in &lt;module&gt;
    load_entry_point('foobar==0.1.0', 'console_scripts', 'foobar')()

[...]

ImportError: No module named 'wont_be_imported_one'.
</code></pre>

<p>UPDATE.
<code>__init__.py</code> has content of</p>

<pre><code>from wont_be_imported_one import wont_be_imported_one
</code></pre>

<p><code>wont_be_imported_one.py</code> has from <code>wont_be_imported_one</code> function which I actually need to import.</p>

<p>In Python 3, <code>import</code>s are absolute by default, and so <code>from wont_be_imported_one import ...</code> inside of <code>foobar</code> will be interpreted as a reference to some module named <code>wont_be_imported_one</code> outside of <code>foobar</code>.  You need to use a relative import instead:</p>

<pre><code>from .wont_be_imported_one import wont_be_imported_one
#    ^ Add this
</code></pre>

<p>See <a href="https://www.python.org/dev/peps/pep-0328/" rel="nofollow">PEP 328</a> for more information.</p>

python setuptools