Why do imports fail in setuptools entry_point scripts, but not in python interpreter?
<p>I have the following project structure:</p>

<pre><code>project
|-project.py
|-__init__.py
|-setup.py
|-lib
  |-__init__.py
  |-project
    |-__init__.py
    |-tools.py
</code></pre>

<p>with <code>project.py</code>:</p>

<pre><code>from project.lib import *

def main():
    print("main")
    tool()

if __name__ == "__main__":
    main()
</code></pre>

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

<pre><code>from setuptools import setup

setup(
    name = "project",
    version="1.0",
    packages = ["project", "project.lib"],
    package_dir = {"project": ".", "project.lib": 'lib/project'},
    entry_points={
        'console_scripts': [
            'project = project.project:main',
        ],
    },
)
</code></pre>

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

<pre><code>def tool():
    print("tool")
</code></pre>

<p>If I run </p>

<pre><code>import project.lib.tools
project.lib.tools.tool()
</code></pre>

<p>it works as expected, but running the command <code>project</code> fails with</p>

<pre><code>Traceback (most recent call last):
  File "/usr/local/bin/project", line 9, in &lt;module&gt;
    load_entry_point('project==1.0', 'console_scripts', 'project')()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 568, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2720, in load_entry_point
    return ep.load()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2380, in load
    return self.resolve()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2386, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "build/bdist.linux-x86_64/egg/project/project.py", line 3, in &lt;module&gt;
ImportError: No module named lib
</code></pre>

<p>I don't understand why the two interpreters don't have the same default import pathes.</p>

<p>The reason for this setup is that I want to be able to <code>import project.lib.tools</code>, but keep the directory structure with <code>lib/project</code>.</p>

<p>The complete <code>distutils</code> documentation seriously doesn't say a word on how one can import packages after they have been distributed (the difference of <code>setuptools</code> and <code>distutils</code> isn't less misterious - no way of knowing whether the behavior of <code>distutils</code> is extended here or not).</p>

<p>I'm using <code>setuptools</code> 18.4-1 with <code>python</code> 2.7 on Ubuntu 15.10.</p>

<p>If I change the project structure and <code>setup.py</code> as suggested in @AnttiHaapala's answer I'm getting </p>

<pre><code>$ project
Traceback (most recent call last):
  File "/usr/local/bin/project", line 9, in &lt;module&gt;
    load_entry_point('project==1.0', 'console_scripts', 'project')()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 568, in load_entry_point
    return get_distribution(dist).load_entry_point(group, name)
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2720, in load_entry_point
    return ep.load()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2380, in load
    return self.resolve()
  File "/usr/local/lib/python2.7/dist-packages/pkg_resources/__init__.py", line 2386, in resolve
    module = __import__(self.module_name, fromlist=['__name__'], level=0)
  File "build/bdist.linux-x86_64/egg/project/project.py", line 3, in &lt;module&gt;
ImportError: No module named lib
</code></pre>