Python Import Error not working
<p>I currently have the following directory structure: </p>

<pre><code>Folder/
  package/
      __init__.py, .. many python files
  subfolder/
       file1.py
</code></pre>

<p>Now, my problem is that I am in the <code>Folder</code> directory. I can run python and then run <code>import package</code>. This works fine. However, in my <code>file1.py</code>, I import <code>package</code> at the beginning but when I run <code>python subfolder/file1.py</code>, it cannot find module named <code>package</code>.</p>

<p>Edited: I currently have __ init__.py (with 2 underscores)</p>

<p>In the latter case, Python cannot find <code>package</code> because it is not visible on <code>sys.path</code>. <code>sys.path</code> will contain amongst other things the parent directory of the script currently being executed.</p>

<p>So when you run Python from <code>Folder</code>, this entry is <code>/path/to/Folder</code> and <code>import package</code> correctly finds the <code>package</code> directory from this. In your second case, this entry will be <code>/path/to/Folder/subfolder</code> and <code>import package</code> will fail because it tries to find <code>/path/to/Folder/subfolder/package</code>.</p>

python import