How to use relative imports in both, module and main
Question: I have the following setup of a library in python:

    
    
    library
      | - __init__.py
      | - lib1.py
      | - ...
      | - tools
            | - __init__.py
            | - testlib1.py
    

so in other words, the directory `library` contain python modules and the
directory `tools`, which is a subdirectory of `library` contains e.g. one file
`testlib1.py`to test the library `lib1.py`.

`testlib1.py` therefore need to import `lib1.py` from the directory above to
do some tests etc., just by calling `python testlib1.py` from somewhere on the
computer, assuming the file is in the search path. In addition, I only want
ONE `PYTHONPATH` to be specified.

But we all know the following idea for `testlib1.py` does not work because the
relative import does not work:

    
    
    from .. import lib1
    ...
    do something with lib1
    

I accept two kind of answers:

  1. An answer which describes how still to be possible to call `testlib1.py` directly as the executing python script. 
  2. An answer that explains a better conceptual setup of of the modules etc, with the premise that everything has to be in the directory `project` and the tools has to be in a _different_ directory than the actual libraries. 

If something is not clear I suggest to ask and I will update the question.


Answer: Try adding a `__init__.py` to the `tools` directory. The relative import
should work.

