title: How to run a Python project using __pycache__ folder?
body: <p>I want to run a Pythonic project using Python compilation (<code>.pyc</code> or <code>__pycache__</code>). In order to do that in <em>Python2</em>, I haven't any problem.</p>
  
  <hr>
  
  <p>Here is a simplified example in a <em>Python2</em> project:</p>
  
  <ul>
  <li><p>Project tree:</p>
  
  <pre><code>test2
  ├── main.py
  └── subfolder
      ├── __init__.py
      └── sub.py
  </code></pre></li>
  <li><p>Compile:</p>
  
  <pre><code>python -m compileall test2
  </code></pre></li>
  <li><p>Project tree after the compile:</p>
  
  <pre><code>test2
  ├── main.py
  ├── main.pyc
  └── subfolder
      ├── __init__.py
      ├── __init__.pyc
      ├── sub.py
      └── sub.pyc
  </code></pre></li>
  <li><p>As you can see, several <code>.pyc</code> manually generated. Now I can run this project using <code>main.pyc</code> as fine, which has a relation with the <code>sub.py</code>:</p>
  
  <pre><code>python main.pyc
  </code></pre>
  
  <p>Out:</p>
  
  <pre><code>Hi
  Bye
  </code></pre></li>
  <li><p>main.py content:</p>
  
  <pre><code>from subfolder import sub
  
  print('Bye')
  </code></pre></li>
  <li><p>sub.py content:</p>
  
  <pre><code>print('Hi')
  </code></pre></li>
  </ul>
  
  <hr>
  
  <p>Now I want to retry this behavior in a <em>Python3</em> project.</p>
  
  <p>Here is a simplified <code>asyncio</code> (available in <em>Python3</em>) project:</p>
  
  <ul>
  <li><p>Project tree:</p>
  
  <pre><code>test3
  ├── main.py
  └── subfolder
      ├── __init__.py
      └── sub.py
  </code></pre></li>
  <li><p>Compile:</p>
  
  <pre><code>python3 -m compileall test3
  </code></pre></li>
  <li><p>Project tree after the compile:</p>
  
  <pre><code>test3
  ├── main.py
  ├── __pycache__
  │   └── main.cpython-36.pyc
  └── subfolder
      ├── __init__.py
      ├── __pycache__
      │   ├── __init__.cpython-36.pyc
      │   └── sub.cpython-36.pyc
      └── sub.py
  </code></pre></li>
  <li><p>As you can see, <code>__pycache__</code> folders manually generated. But I cannot run this project using <code>main.cpython-36.pyc</code> which has a relation with <code>subfolder</code>:</p>
  
  <pre><code>cd test3/__pycache__
  python3 main.cpython-36.pyc
  </code></pre>
  
  <p>Out (I expected that produced the <code>Hi Bye</code> message):</p>
  
  <pre><code>Traceback (most recent call last):
    File "test3/main.py", line 2, in &lt;module&gt;
  ModuleNotFoundError: No module named 'subfolder'
  </code></pre></li>
  <li><p>main.py content:</p>
  
  <pre><code>import asyncio
  from subfolder import sub
  
  async def myCoroutine():
      print("Bye")
  
  def main():
      loop = asyncio.get_event_loop()
      loop.run_until_complete(myCoroutine())
      loop.close()
  
  main()
  </code></pre></li>
  <li><p>sub.py content:</p>
  
  <pre><code>print('Hi')
  </code></pre></li>
  </ul>
  
  <hr>
  
  <h1>Question:</h1>
  
  <p>How can I run this project (above <em>Python3</em> project) using <code>__pycache__</code> folder?</p>
  
  <p>Or</p>
  
  <p>How can I run a <em>Python3</em> project with the relation between subfolders using python compilation?</p>
  
  <hr>
  
  <p>[<strong>NOTE</strong>]:</p>
  
  <ul>
  <li><p>I cannot use the <code>python compileall</code> (<em>Python2</em> compile) in the above <code>Python3</code> project due to the <code>asyncio</code> method. </p></li>
  <li><p>My Python(s) version is <em>Python2.7</em> and <em>Python3.6</em></p></li>
  </ul>