Posts Tagged ‘project structure’

Relative import in Python

September 6, 2011 Leave a comment

The following post is based on nosklo’s answer who explained relative imports very nicely in this thread.

Imagine the following project structure:
app/ ->
    package_a/ ->
    package_b/ ->

Problem: how to use from


  1. you run: python
  2. does: import app.package_a.module_a
  3. does: import app.package_b.module_b

Alternatively, 2 or 3 could use: from app.package_a import module_a

That will work as long as you have app in your PYTHONPATH. could be anywhere then.”