title: Importing library classes in Python
body: <p>I have following project hierarchy:</p>
  
  <pre><code>project_dir
    lib
      __init__.py
      ...
      some_script.py
      ...
      agent
        __init__.py
        ...
        errors.py
        some_agent_script.py
        ...
  </code></pre>
  
  <p>There is the SomeException class definition in lib/agent/erros.py
  I use following code to import them inside lib/agent/some_agent_script.py:</p>
  
  <pre><code>from errors import SomeException
  </code></pre>
  
  <p>Also I use following code to import in lib/some_script.py</p>
  
  <pre><code>from agent.errors import SomeException
  </code></pre>
  
  <p>The problem is when I raise a SomeException in lib/agent/some_agent_script.py then lib/some_script.py can not catch it in an except block:</p>
  
  <pre><code>try:
      # Here comes a call to lib/agent/some_agent_script.py function
      # that raises SomeException
  except SomeException, exc:
      # Never goes here
      print(exc)
  except Exception, exc:
      print(exc.__class__.__name__) # prints "SomeException"
  
      # Let's print id's
      print(id(exc.__class__))
      print(id(SomeException))
      # They are different!
  
      # Let's print modules list
      pprint.pprint(sys.modules)
  </code></pre>
  
  <p>I can see in sys.modules that erros module was imported twice: the first is with 'agent.errors' key and the second is with 'lib.agent.errors' key</p>
  
  <p>The following code goes right, but it's not a beautiful solution:</p>
  
  <pre><code>agent_errors = sys.modules.get('agent.errors')
  from agent_errors import SomeException
  
  try:
      # Here comes a call to lib/agent/some_agent_script.py function
  except SomeException:
      print('OK')
  </code></pre>
  
  <p>What should I do to make this module not to import twice?</p>