How to fix "ImportError: No module named ..." error in Python?
<p>What is the correct way to fix this ImportError error?</p>

<p>I have the following directory structure:</p>

<pre><code>/home/bodacydo
/home/bodacydo/work
/home/bodacydo/work/project
/home/bodacydo/work/project/programs
/home/bodacydo/work/project/foo
</code></pre>

<p>And I am in the directory</p>

<pre><code>/home/bodacydo/work/project
</code></pre>

<p>Now if I type</p>

<pre><code>python ./programs/my_python_program.py
</code></pre>

<p>I instantly get</p>

<pre><code>ImportError: No module named foo.tasks
</code></pre>

<p>The <code>./programs/my_python_program.py</code> contains the following line:</p>

<pre><code>from foo.tasks import my_function
</code></pre>

<p>I can't understand why python won't find <code>./foo/tasks.py</code> - it's there.</p>

<p>If I do it from the Python shell, then it works:</p>

<pre><code>python
&gt;&gt;&gt; from foo.tasks import my_function
</code></pre>

<p>It only doesn't work if I call it via <code>python ./programs/my_python_program.py</code> script.</p>

<p>Help me fix it!</p>

<p>Thanks, Boda Cydo.</p>
