Import modules from different folder (python)
Question: I have a folder, which contains two separate folders, one of which holds some
python modules, and the other one holds a python script that uses those
modules:

    
    
    parentFolder/
        lib/
           __init__.py
           readFile.py
           writeFile.py
        folder/
           run.py
    

The `__init__.py` file is empty. In `run.py`, I have the following:

    
    
    from ..lib import readFile
    
    data = readFile('file.dat')
    

This gives me the error

    
    
    Traceback (most recent call last):
      File "run.py", line 1, in <module>
        from ..lib import readFile
    ValueError: Attempted relative import in non-package 
    

What am I missing?


Answer: You need to add `__init__.py` files (can be empty) to each of the directories
to make them a package. See the
[documentation](https://docs.python.org/2/tutorial/modules.html#packages) for
more details.

